Cataclysm BN
item Class Reference

#include <item.h>

Inheritance diagram for item:
visitable< item >

Classes

class  craft_data
 Data for items that represent in-progress crafts. More...
 
struct  default_charges_tag
 Suppress randomization and always start with default quantity of charges. More...
 
struct  solitary_tag
 Default (or randomized) charges except if counted by charges then only one charge. More...
 
struct  sound_data
 

Public Types

using FlagsSetType = cata::flat_set< std::string >
 
using archive_type_tag = io::object_archive_tag
 

Public Member Functions

 item ()
 
 item (item &&)
 
 item (const item &)
 
itemoperator= (item &&)
 
itemoperator= (const item &)
 
 item (const itype_id &id, time_point turn=calendar::turn, int qty=-1)
 
 item (const itype *type, time_point turn=calendar::turn, int qty=-1)
 
 item (const itype_id &id, time_point turn, default_charges_tag)
 
 item (const itype *type, time_point turn, default_charges_tag)
 
 item (const itype_id &id, time_point turn, solitary_tag)
 
 item (const itype *type, time_point turn, solitary_tag)
 
 item (const recipe *rec, int qty, std::list< item > items, std::vector< item_comp > selections)
 For constructing in-progress crafts. More...
 
template<typename... Args>
 item (const std::string &itype, Args &&... args)
 
 ~item ()
 
safe_reference< itemget_safe_reference ()
 Return a pointer-like type that's automatically invalidated if this item is destroyed or assigned-to. More...
 
itemconvert (const itype_id &new_type)
 Filter converting this instance to another type preserving all other aspects. More...
 
itemdeactivate (const Character *ch=nullptr, bool alert=true)
 Filter converting this instance to the inactive type If the item is either inactive or cannot be deactivated is a no-op. More...
 
itemactivate ()
 Filter converting instance to active state. More...
 
units::energy mod_energy (const units::energy &qty)
 Add or remove energy from a battery. More...
 
itemammo_set (const itype_id &ammo, int qty=-1)
 Filter setting the ammo for this instance Any existing ammo is removed. More...
 
itemammo_unset ()
 Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-op For items reloading using magazines any empty magazine remains present. More...
 
itemset_damage (int qty)
 Filter setting damage constrained by min_damage and max_damage. More...
 
item split (int qty)
 Splits a count-by-charges item always leaving source item with minimum of 1 charge. More...
 
const mtypeget_mtype () const
 
void set_mtype (const mtype *m)
 Sets the monster type associated with this item (corpse). More...
 
bool is_corpse () const
 Whether this is a corpse item. More...
 
bool can_revive () const
 Whether this is a corpse that can be revived. More...
 
bool ready_to_revive (const tripoint &pos) const
 Whether this corpse should revive now. More...
 
bool is_money () const
 
nc_color color () const
 Returns the default color of the item (e.g. More...
 
nc_color color_in_inventory () const
 Returns the color of the item depending on usefulness for the player character, e.g. More...
 
nc_color color_in_inventory (const player &p) const
 Returns the color of the item depending on usefulness for the passed player, e.g. More...
 
std::string tname (unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
 Return the (translated) item name. More...
 
std::string display_money (unsigned int quantity, unsigned int total, const std::optional< unsigned int > &selected=std::nullopt) const
 
std::string display_name (unsigned int quantity=1) const
 Returns the item name and the charges or contained charges (if the item can have charges at all). More...
 
std::vector< iteminfoinfo () const
 Return all the information about the item and its type as a vector. More...
 
std::vector< iteminfoinfo (int batch) const
 
std::vector< iteminfoinfo (const iteminfo_query &parts, int batch, temperature_flag temperature) const
 
std::vector< iteminfoinfo (temperature_flag temperature) const
 
std::string info_string () const
 As info, but as a string rather than a vector of properties. More...
 
std::string info_string (const iteminfo_query &parts, int batch=1, temperature_flag temperature=temperature_flag::TEMP_NORMAL) const
 
void basic_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void med_info (const item *med_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void food_info (const item *food_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug, temperature_flag temperature) const
 
void magazine_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void ammo_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void gun_info (const item *mod, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void gunmod_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_protection_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void animal_armor_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_fit_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void book_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void battery_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void container_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void tool_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void component_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void repair_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void disassembly_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void qualities_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void bionic_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void combat_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void contents_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void final_info (std::vector< iteminfo > &info, const iteminfo_query &parts, int batch, bool debug) const
 
float simulate_burn (fire_data &frd) const
 Calculate all burning calculations, but don't actually apply them to item. More...
 
bool burn (fire_data &frd)
 Burns the item. More...
 
const item_categoryget_category () const
 
bool reload (player &u, item_location loc, int qty)
 Reload item using ammo from location returning true if successful. More...
 
template<typename Archive >
void io (Archive &)
 
void serialize (JsonOut &json) const
 
void deserialize (JsonIn &jsin)
 
const std::string & symbol () const
 
int price (bool practical) const
 Returns the monetary value of an item. More...
 
bool display_stacked_with (const item &rhs, bool check_components=false) const
 Whether two items should stack when displayed in a inventory menu. More...
 
bool stacks_with (const item &rhs, bool check_components=false, bool skip_type_check=false) const
 
bool merge_charges (const item &rhs)
 Merge charges of the other item into this item. More...
 
units::mass weight (bool include_contents=true, bool integral=false) const
 
units::volume volume (bool integral=false) const
 Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge. More...
 
units::volume base_volume () const
 Simplified, faster volume check for when processing time is important and exact volume is not. More...
 
units::volume corpse_volume (const mtype *corpse) const
 Volume check for corpses, helper for base_volume(). More...
 
int lift_strength () const
 Required strength to be able to successfully lift the item unaided by equipment. More...
 
Melee

The functions here assume the item is used in melee, even if's a gun or not a weapon at all.

Because the functions apply to all types of items, several of the is_* functions here may return true for the same item. This only indicates that it can be used in various ways.

int attack_cost () const
 Base number of moves (Creature::moves) that a single melee attack with this items takes. More...
 
int damage_melee (damage_type dt) const
 Damage of given type caused when this item is used as melee weapon. More...
 
damage_instance base_damage_melee () const
 All damage types this item deals when used in melee (no skill modifiers etc. More...
 
damage_instance base_damage_thrown () const
 All damage types this item deals when thrown (no skill modifiers etc. More...
 
double effective_dps (const player &guy, const monster &mon) const
 Calculate the item's effective damage per second past armor when wielded by a character against a monster. More...
 
std::map< std::string, double > dps (bool for_display, bool for_calc, const player &guy) const
 calculate effective dps against a stock set of monsters. More...
 
std::map< std::string, double > dps (bool for_display, bool for_calc) const
 
double average_dps (const player &guy) const
 return the average dps of the weapon against evaluation monsters More...
 
double ideal_ranged_dps (const Character &who, gun_mode &mode) const
 
bool is_two_handed (const Character &guy) const
 Whether the character needs both hands to wield this item. More...
 
bool is_melee (damage_type dt) const
 Is this item an effective melee weapon for the given damage type? More...
 
bool is_melee () const
 Is this item an effective melee weapon for any damage type? More...
 
skill_id melee_skill () const
 The most relevant skill used with this melee weapon. More...
 
int reach_range (const Character &guy) const
 Max range of melee attack this weapon can be used for. More...
 
void set_countdown (int num_turns)
 Sets time until activation for an item that will self-activate in the future. More...
 
bool use_charges (const itype_id &what, int &qty, std::list< item > &used, const tripoint &pos, const std::function< bool(const item &)> &filter=return_true< item >)
 Consumes specified charges (or fewer) from this and any contained items. More...
 
bool on_drop (const tripoint &pos)
 Invokes item type's itype::drop_action. More...
 
bool on_drop (const tripoint &pos, map &map)
 Invokes item type's itype::drop_action. More...
 
bool use_amount (const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
 Consume a specific amount of items of a specific type. More...
 
bool allow_crafting_component () const
 Permits filthy components, should only be used as a helper in creating filters. More...
 
Containers

Containers come in two flavors:

bool is_container () const
 Whether this is container. More...
 
bool is_watertight_container () const
 Whether this is a container which can be used to store liquids. More...
 
bool is_container_empty () const
 Whether this item has no contents at all. More...
 
bool is_non_resealable_container () const
 Whether removing this item's contents will permanently alter it. More...
 
bool is_container_full (bool allow_bucket=false) const
 Whether this item has no more free capacity for its current content. More...
 
void fill_with (item &liquid, int amount=INFINITE_CHARGES)
 Fill item with liquid up to its capacity. More...
 
int get_remaining_capacity_for_liquid (const item &liquid, bool allow_bucket=false, std::string *err=nullptr) const
 How much more of this liquid (in charges) can be put in this container. More...
 
int get_remaining_capacity_for_liquid (const item &liquid, const Character &p, std::string *err=nullptr) const
 
units::volume get_container_capacity () const
 It returns the total capacity (volume) of the container for liquids. More...
 
units::volume get_total_capacity () const
 It returns the maximum volume of any contents, including liquids, ammo, magazines, weapons, etc. More...
 
void put_in (const item &payload)
 Puts the given item into this one, no checks are performed. More...
 
item in_its_container () const
 Returns this item into its default container. More...
 
item in_container (const itype_id &container_type) const
 
bool item_has_uses_recursive () const
 
bool is_funnel_container (units::volume &bigger_than) const
 Funnel related functions. More...
 
void add_rain_to_container (bool acid, int charges=1)
 Add charge(s) of rain to given container, possibly contaminating it. More...
 
int get_quality (const quality_id &id) const
 
std::map< quality_id, int > get_qualities () const
 
bool count_by_charges () const
 
int count () const
 If count_by_charges(), returns charges, otherwise 1. More...
 
bool craft_has_charges ()
 
void mod_charges (int mod)
 Modify the charges of this item, only use for items counted by charges! The item must have enough charges for this (>= quantity) and be counted by charges. More...
 
bool actualize_rot (const tripoint &pnt, temperature_flag temperature, const weather_manager &weather)
 Whether the item has to be removed as it has rotten away completely. More...
 
time_duration calc_rot (time_point time, int temp) const
 Returns rot of the item since last rot calculation. More...
 
time_duration minimum_freshness_duration (temperature_flag temperature) const
 Time that this item is guaranteed to stay fresh. More...
 
void mod_last_rot_check (time_duration processing_duration)
 This is part of a workaround so that items don't rot away to nothing if the smoking rack is outside the reality bubble. More...
 
bool process_rot (const tripoint &pos)
 Update temperature for things like food Update rot for things that perish All items that rot also have temperature. More...
 
bool process_rot (bool seals, const tripoint &pos, player *carrier, temperature_flag flag, const weather_manager &weather_generator)
 
int get_comestible_fun () const
 
bool goes_bad () const
 whether an item is perishable (can rot) More...
 
bool goes_bad_after_opening () const
 whether an item is perishable (can rot), even if it is currently in a preserving container More...
 
time_duration get_shelf_life () const
 Get the shelf life of the item. More...
 
double get_relative_rot () const
 Get rot value relative to shelf life (or 0 if item does not spoil) More...
 
void set_relative_rot (double val)
 Set current item rot relative to shelf life (no-op if item does not spoil) More...
 
void set_rot (time_duration val)
 
int spoilage_sort_order () const
 Get time left to rot, ignoring fridge. More...
 
bool is_fresh () const
 an item is fresh if it is capable of rotting but still has a long shelf life remaining More...
 
bool is_going_bad () const
 an item is about to become rotten when shelf life has nearly elapsed More...
 
bool rotten () const
 returns true if item is now rotten after all shelf life has elapsed More...
 
bool has_rotten_away () const
 Whether the item has enough rot that it should get removed. More...
 
time_duration get_rot () const
 
void mod_rot (const time_duration &val)
 
time_duration brewing_time () const
 Time for this item to be fully fermented. More...
 
const std::vector< itype_id > & brewing_results () const
 The results of fermenting this item. More...
 
bool detonate (const tripoint &p, std::vector< item > &drops)
 Detonates the item and adds remains (if any) to drops. More...
 
bool will_explode_in_fire () const
 
Material(s) of the item

Each item is made of one or more materials (material_type).

Materials have properties that affect properties of the item (e.g. resistance against certain damage types).

Corpses inherit the material of the monster type.

const material_typeget_random_material () const
 Get a material reference to a random material that this item is made of. More...
 
const material_typeget_base_material () const
 Get the basic (main) material of this item. More...
 
const std::vector< material_id > & made_of () const
 The ids of all the materials this is made of. More...
 
const std::map< quality_id, int > & quality_of () const
 The ids of all the qualities this contains. More...
 
std::vector< const material_type * > made_of_types () const
 Same as made_of(), but returns the material_type directly. More...
 
bool made_of_any (const std::set< material_id > &mat_idents) const
 Check we are made of at least one of a set (e.g. More...
 
bool only_made_of (const std::set< material_id > &mat_idents) const
 Check we are made of only the materials (e.g. More...
 
bool made_of (const material_id &mat_ident) const
 Check we are made of this material (e.g. More...
 
bool contents_made_of (phase_id phase) const
 If contents nonempty, return true if item phase is same, else false. More...
 
bool made_of (phase_id phase) const
 Are we solid, liquid, gas, plasma? More...
 
std::vector< item_compget_uncraft_components () const
 Returns a list of components used to craft this item or the default components if it wasn't player-crafted. More...
 
bool conductive () const
 Whether the items is conductive. More...
 
bool flammable (int threshold=0) const
 Whether the items is flammable. More...
 
bool reinforceable () const
 Whether the item can be repaired beyond normal health. More...
 
int acid_resist (bool to_self=false, int base_env_resist=0) const
 Resistance against different damage types (damage_type). More...
 
int fire_resist (bool to_self=false, int base_env_resist=0) const
 
int bash_resist (bool to_self=false) const
 
int cut_resist (bool to_self=false) const
 
int stab_resist (bool to_self=false) const
 
int bullet_resist (bool to_self=false) const
 
void mitigate_damage (damage_unit &du) const
 Assuming that specified du hit the armor, reduce du based on the item's resistance to the damage type. More...
 
int damage_resist (damage_type dt, bool to_self=false) const
 Resistance provided by this item against damage type given by an enum. More...
 
int chip_resistance (bool worst=false) const
 Returns resistance to being damaged by attack against the item itself. More...
 
int damage () const
 How much damage has the item sustained? More...
 
int damage_level (int max) const
 Scale item damage to the given number of levels. More...
 
int min_damage () const
 Minimum amount of damage to an item (state of maximum repair) More...
 
int max_damage () const
 Maximum amount of damage to an item (state before destroyed) More...
 
float get_relative_health () const
 Relative item health. More...
 
bool mod_damage (int qty, damage_type dt)
 Apply damage to const itemrained by min_damage and max_damage. More...
 
bool mod_damage (int qty)
 same as other mod_damage, but uses DT_NULL as damage type. More...
 
bool inc_damage (damage_type dt)
 Increment item damage by itype::damage_scale constrained by max_damage. More...
 
bool inc_damage ()
 same as other inc_damage, but uses DT_NULL as damage type. More...
 
nc_color damage_color () const
 Provide color for UI display dependent upon current item damage level. More...
 
std::string damage_symbol () const
 Provide prefix symbol for UI display dependent upon current item damage level. More...
 
std::string durability_indicator (bool include_intact=false) const
 Provides a prefix for the durability state of the item. More...
 
const std::set< itype_id > & repaired_with () const
 If possible to repair this item what tools could potentially be used for this purpose? More...
 
bool already_used_by_player (const player &p) const
 Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific player. More...
 
void mark_as_used_by_player (const player &p)
 Marks the item as being used by this specific player, it remains unmarked for other players. More...
 
bool is_filthy () const
 Marks the item as filthy, so characters with squeamish trait can't wear it. More...
 
bool process (player *carrier, const tripoint &pos, bool activate, temperature_flag flag=temperature_flag::TEMP_NORMAL)
 This is called once each turn. More...
 
bool process (player *carrier, const tripoint &pos, bool activate, temperature_flag flag, const weather_manager &weather_generator)
 
std::optional< tripointget_cable_target (Character *p, const tripoint &pos) const
 Gets the point (vehicle tile) the cable is connected to. More...
 
void reset_cable (player *p)
 Helper to bring a cable back to its initial state. More...
 
bool needs_processing () const
 Whether the item should be processed (by calling process). More...
 
int processing_speed () const
 The rate at which an item should be processed, in number of turns between updates. More...
 
void process_artifact (player *carrier, const tripoint &pos)
 Process and apply artifact effects. More...
 
void process_relic (Character &carrier)
 
bool destroyed_at_zero_charges () const
 
bool is_null () const
 
bool is_comestible () const
 
bool is_food () const
 
bool is_food_container () const
 
bool is_med_container () const
 
bool is_ammo_container () const
 
bool is_medication () const
 
bool is_bionic () const
 
bool is_magazine () const
 
bool is_battery () const
 
bool is_ammo_belt () const
 
bool is_bandolier () const
 
bool is_holster () const
 
bool is_ammo () const
 
bool is_pet_armor (bool on_pet=false) const
 
bool is_armor () const
 
bool is_book () const
 
bool is_map () const
 
bool is_salvageable () const
 
bool is_craft () const
 
bool is_deployable () const
 
bool is_tool () const
 
bool is_transformable () const
 
bool is_artifact () const
 
bool is_relic () const
 
bool is_bucket () const
 
bool is_bucket_nonempty () const
 
bool is_brewable () const
 
bool is_engine () const
 
bool is_wheel () const
 
bool is_fuel () const
 
bool is_toolmod () const
 
bool is_faulty () const
 
bool is_irremovable () const
 
bool is_unarmed_weapon () const
 
itemget_food ()
 
const itemget_food () const
 
int wind_resist () const
 How resistant clothes made of this material are to wind (0-100) More...
 
std::set< fault_idfaults_potential () const
 What faults can potentially occur with this item? More...
 
int wheel_area () const
 Returns the total area of this wheel or 0 if it isn't one. More...
 
float fuel_energy () const
 Returns energy of one charge of this item as fuel for an engine. More...
 
std::string fuel_pump_terrain () const
 Returns the string of the id of the terrain that pumps this fuel, if any. More...
 
bool has_explosion_data () const
 
struct fuel_explosion get_explosion_data ()
 
bool can_contain (const item &it) const
 Can this item have given item/itype as content? More...
 
bool can_contain (const itype &tp) const
 
bool is_reloadable () const
 Is it ever possible to reload this item? Only the base item is considered with any mods ignored. More...
 
bool can_reload_with (const ammotype &ammo) const
 Returns true if this item can be reloaded with specified ammo type, ignoring currently loaded ammo. More...
 
bool can_reload_with (const itype_id &ammo) const
 Returns true if this item can be reloaded with specified ammo item, ignoring currently loaded ammo. More...
 
bool is_reloadable_with (const itype_id &ammo) const
 Returns true if this item can be reloaded with specified ammo type at this moment. More...
 
bool can_unload_liquid () const
 Returns true if not empty if it's liquid, it's not currently frozen in resealable container. More...
 
bool is_dangerous () const
 
bool is_tainted () const
 Is item derived from a zombie? More...
 
bool is_soft () const
 Is this item flexible enough to be worn on body parts like antlers? More...
 
bool has_effect_when_wielded (art_effect_passive effect) const
 Does the item provide the artifact effect when it is wielded? More...
 
bool has_effect_when_worn (art_effect_passive effect) const
 Does the item provide the artifact effect when it is worn? More...
 
bool has_effect_when_carried (art_effect_passive effect) const
 Does the item provide the artifact effect when it is carried? More...
 
void set_snippet (const snippet_id &id)
 Set the snippet text (description) of this specific item, using the snippet library. More...
 
bool operator< (const item &other) const
 
std::string components_to_string () const
 List of all components in printable form, empty if this item has no components. More...
 
uint64_t make_component_hash () const
 Creates a hash from the itype_ids of this item's components. More...
 
const itype_idtypeId () const
 return the unique identifier of the items underlying type More...
 
const itemget_contained () const
 Return a contained item (if any and only one). More...
 
bool spill_contents (Character &c)
 Unloads the item's contents. More...
 
bool spill_contents (const tripoint &pos)
 Unloads the item's contents. More...
 
bool can_holster (const item &obj, bool ignore=false) const
 Checks if item is a holster and currently capable of storing obj. More...
 
void on_wear (Character &p)
 Callback when a character starts wearing the item. More...
 
void on_takeoff (Character &p)
 Callback when a character takes off an item. More...
 
void on_wield (player &p, int mv=0)
 Callback when a player starts wielding the item. More...
 
void on_pickup (Character &p)
 Callback when a player starts carrying the item. More...
 
void on_contents_changed ()
 Callback when contents of the item are affected in any way other than just processing. More...
 
void on_damage (int qty, damage_type dt)
 Callback immediately before an item is damaged. More...
 
std::vector< trait_idmutations_from_wearing (const Character &guy) const
 
std::string type_name (unsigned int quantity=1) const
 Name of the item type (not the item), with proper plural. More...
 
int charges_per_volume (const units::volume &vol) const
 Number of (charges of) this item that fit into the given volume. More...
 
Item variables

Item variables can be used to store any value in the item.

The storage is persistent, it remains through saving & loading, it is copied when the item is moved etc. Each item variable is referred to by its name, so make sure you use a name that is not already used somewhere. You can directly store integer, floating point and string values. Data of other types must be converted to one of those to be stored. The set_var functions override the existing value. The get_var function return the value (if the variable exists), or the default value otherwise. The type of the default value determines which get_var function is used. All numeric values are returned as doubles and may be cast to the desired type. int v = itm.get_var("v", 0); // v will be an int double d = itm.get_var("v", 0.0); // d will be a double std::string s = itm.get_var("v", ""); // s will be a std::string // no default means empty string as default: auto n = itm.get_var("v"); // v will be a std::string

void set_var (const std::string &name, int value)
 
void set_var (const std::string &name, long long value)
 
void set_var (const std::string &name, long value)
 
void set_var (const std::string &name, double value)
 
double get_var (const std::string &name, double default_value) const
 
void set_var (const std::string &name, const tripoint &value)
 
tripoint get_var (const std::string &name, const tripoint &default_value) const
 
void set_var (const std::string &name, const std::string &value)
 
std::string get_var (const std::string &name, const std::string &default_value) const
 
std::string get_var (const std::string &name) const
 Get the variable, if it does not exists, returns an empty string. More...
 
bool has_var (const std::string &name) const
 Whether the variable is defined at all. More...
 
void erase_var (const std::string &name)
 Erase the value of the given variable. More...
 
void clear_vars ()
 Removes all item variables. More...
 
Item flags

If you use any new flags, add them to flags.json, add a comment to doc/JSON_FLAGS.md and make sure your new flag does not conflict with any existing flag.

Item flags are taken from the item type (itype::item_tags), but also from the item itself (item_tags). The item has the flag if it appears in either set.

Gun mods that are attached to guns also contribute their flags to the gun item.

bool has_flag (const std::string &flag) const
 
bool has_flag (const flag_str_id &flag) const
 
template<typename Container , typename T = std::decay_t<decltype( *std::declval<const Container &>().begin() )>>
bool has_any_flag (const Container &flags) const
 
bool has_own_flag (const std::string &flag) const
 Checks whether item itself has given flag (doesn't check item type or gunmods). More...
 
const FlagsSetTypeget_flags () const
 returs read-only set of flags of this item (not including flags from item type or gunmods) More...
 
itemset_flag (const std::string &flag)
 Idempotent filter setting an item specific flag. More...
 
itemunset_flag (const std::string &flag)
 Idempotent filter removing an item specific flag. More...
 
itemset_flag_recursive (const std::string &flag)
 Idempotent filter recursively setting an item specific flag on this item and its components. More...
 
void unset_flags ()
 Removes all item specific flags. More...
 
bool has_fault (const fault_id &fault) const
 Does this item have the specified fault. More...
 
Item properties

Properties are specific to an item type so unlike flags the meaning of a property may not be the same for two different item types.

Each item type can have multiple properties however duplicate property names are not permitted.

bool has_property (const std::string &prop) const
 
std::string get_property_string (const std::string &prop, const std::string &def="") const
 Get typed property for item. More...
 
int64_t get_property_int64_t (const std::string &prop, int64_t def=0) const
 
Light emitting items

Items can emit light either through the definition of their type (itype::light_emission) or through an item specific light data (light).

bool getlight (float &luminance, units::angle &width, units::angle &direction) const
 Directional light emission of the item. More...
 
int getlight_emit () const
 How much light (see lightmap.cpp) the item emits (it's assumed to be circular). More...
 
bool is_emissive () const
 Whether the item emits any light at all. More...
 
Seed data.
bool is_seed () const
 Whether this is actually a seed, the seed functions won't be of much use for non-seeds. More...
 
time_duration get_plant_epoch () const
 Time it takes to grow from one stage to another. More...
 
std::string get_plant_name () const
 The name of the plant as it appears in the various informational menus. More...
 
Armor related functions.

The functions here refer to values from islot_armor.

They only apply to armor items, those items can be worn. The functions are safe to call for any item, for non-armor they return a default value.

bool covers (body_part bp) const
 Whether this item (when worn) covers the given body part. More...
 
bool covers (const bodypart_id &bp) const
 
body_part_set get_covered_body_parts () const
 Bitset of all covered body parts. More...
 
body_part_set get_covered_body_parts (side s) const
 Bitset of all covered body parts, from a specific side. More...
 
bool is_sided () const
 Returns true if item is armor and can be worn on different sides of the body. More...
 
side get_side () const
 Returns side item currently worn on. More...
 
bool set_side (side s)
 Change the side on which the item is worn. More...
 
bool swap_side ()
 Swap the side on which the item is worn. More...
 
int get_warmth () const
 Returns the warmth value that this item has when worn. More...
 
int get_thickness () const
 Returns the islot_armor::thickness value, or 0 for non-armor. More...
 
layer_level get_layer () const
 Returns clothing layer for item. More...
 
int get_coverage () const
 Returns the relative coverage that this item has when worn. More...
 
int get_encumber_when_containing (const Character &, const units::volume &contents_volume) const
 Returns the encumbrance value that this item has when worn by given player, when containing a particular volume of contents. More...
 
int get_encumber (const Character &) const
 Returns the encumbrance value that this item has when worn by given player. More...
 
units::volume get_storage () const
 Returns the storage amount (islot_armor::storage) that this item provides when worn. More...
 
float get_weight_capacity_modifier () const
 Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides when worn. More...
 
units::mass get_weight_capacity_bonus () const
 Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides when worn. More...
 
int get_env_resist (int override_base_resist=0) const
 Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides when worn. More...
 
int get_base_env_resist_w_filter () const
 Returns the base resistance to environmental effects if an item (for example a gas mask) requires a gas filter to operate and this filter is installed. More...
 
bool is_power_armor () const
 Whether this is a power armor item. More...
 
const islot_armorfind_armor_data () const
 If this is an armor item, return its armor data. More...
 
bool is_worn_only_with (const item &it) const
 Returns true whether this item can be worn only when. More...
 
Pet armor related functions.

The functions here refer to values from islot_pet_armor.

They only apply to pet armor items, those items can be worn by pets. The functions are safe to call for any item, for non-pet armor they return a default value.

units::volume get_pet_armor_max_vol () const
 
units::volume get_pet_armor_min_vol () const
 
bodytype_id get_pet_armor_bodytype () const
 
Books

Book specific functions, apply to items that are books.

int get_chapters () const
 How many chapters the book has (if any). More...
 
int get_remaining_chapters (const Character &ch) const
 Get the number of unread chapters. More...
 
void mark_chapter_as_read (const Character &ch)
 Mark one chapter of the book as read by the given player. More...
 
std::vector< std::pair< const recipe *, int > > get_available_recipes (const player &u) const
 Enumerates recipes available from this book and the skill level required to use them. More...
 
Martial art techniques

See martialarts.h for further info.

bool has_technique (const matec_id &tech) const
 Whether the item supports a specific martial art technique (either through its type, or through its individual techniques). More...
 
std::set< matec_idget_techniques () const
 Returns all the martial art techniques that this items supports. More...
 
void add_technique (const matec_id &tech)
 Add the given technique to the item specific techniques. More...
 
std::vector< item * > toolmods ()
 Returns all toolmods currently attached to this item (always empty if item not a tool) More...
 
std::vector< const item * > toolmods () const
 
Gun and gunmod functions

Gun and gun mod functions.

Anything stated to apply to guns, applies to auxiliary gunmods as well (they are some kind of gun). Non-guns are items that are neither gun nor auxiliary gunmod.

bool is_gunmod () const
 
bool is_gun () const
 Can this item be used to perform a ranged attack? More...
 
units::energy energy_remaining () const
 Quantity of energy currently loaded in tool or battery. More...
 
int ammo_remaining () const
 Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod. More...
 
int ammo_capacity () const
 Maximum quantity of ammunition loadable for tool, gun or auxiliary gunmod. More...
 
int ammo_capacity (bool potential_capacity) const
 
int ammo_required () const
 Quantity of ammunition consumed per usage of tool or with each shot of gun. More...
 
bool ammo_sufficient (int qty=1) const
 Check if sufficient ammo is loaded for given number of uses. More...
 
int ammo_consume (int qty, const tripoint &pos)
 Consume ammo (if available) and return the amount of ammo that was consumed. More...
 
const itypeammo_data () const
 Specific ammo data, returns nullptr if item is neither ammo nor loaded with any. More...
 
itype_id ammo_current () const
 Specific ammo type, returns "null" if item is neither ammo nor loaded with any. More...
 
const std::set< ammotype > & ammo_types (bool conversion=true) const
 Set of ammo types (ammunition_type) used by item. More...
 
ammotype ammo_type () const
 Ammo type of an ammo item. More...
 
itype_id ammo_default (bool conversion=true) const
 Get default ammo used by item or a null id if item does not have a default ammo type. More...
 
itype_id common_ammo_default (bool conversion=true) const
 Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists. More...
 
std::set< ammo_effect_str_idammo_effects (bool with_ammo=true) const
 Get ammo effects for item optionally inclusive of any resulting from the loaded ammo. More...
 
std::string ammo_sort_name () const
 
int casings_count () const
 How many spent casings are contained within this item? More...
 
void casings_handle (const std::function< bool(item &)> &func)
 Apply predicate to each contained spent casing removing it if predicate returns true. More...
 
bool magazine_integral () const
 Does item have an integral magazine (as opposed to allowing detachable magazines) More...
 
itype_id magazine_default (bool conversion=true) const
 Get the default magazine type (if any) for the current effective ammo type. More...
 
std::set< itype_idmagazine_compatible (bool conversion=true) const
 Get compatible magazines (if any) for this item. More...
 
itemmagazine_current ()
 Currently loaded magazine (if any) More...
 
const itemmagazine_current () const
 
std::vector< item * > gunmods ()
 Returns all gunmods currently attached to this item (always empty if item not a gun) More...
 
std::vector< const item * > gunmods () const
 
itemgunmod_find (const itype_id &mod)
 Get first attached gunmod matching type or nullptr if no such mod or item is not a gun. More...
 
const itemgunmod_find (const itype_id &mod) const
 
ret_val< bool > is_gunmod_compatible (const item &mod) const
 
std::map< gun_mode_id, gun_modegun_all_modes () const
 Get all possible modes for this gun inclusive of any attached gunmods. More...
 
gun_mode gun_get_mode (const gun_mode_id &mode) const
 Check if gun supports a specific mode returning an invalid/empty mode if not. More...
 
gun_mode gun_current_mode () const
 Get the current mode for this gun (or an invalid mode if item is not a gun) More...
 
gun_mode_id gun_get_mode_id () const
 Get id of mode a gun is currently set to, e.g. More...
 
bool gun_set_mode (const gun_mode_id &mode)
 Try to set the mode for a gun, returning false if no such mode is possible. More...
 
void gun_cycle_mode ()
 Switch to the next available firing mode. More...
 
int sight_dispersion () const
 Get lowest dispersion of either integral or any attached sights. More...
 
sound_data gun_noise (bool burst=false) const
 Returns the sound of the gun being fired. More...
 
bool is_silent () const
 Whether this is a (nearly) silent gun (a tiny bit of sound is allowed). More...
 
int gun_range (const player *p) const
 The weapons range in map squares. More...
 
int gun_range (bool with_ammo=true) const
 Summed range value of a gun, including values from mods. More...
 
double gun_recoil_multiplier (bool bipod=false) const
 Get multiplier on recoil considering handling and attached gunmods. More...
 
int gun_recoil (bool bipod=false) const
 Get effective recoil considering handling, loaded ammo and effects of attached gunmods. More...
 
damage_instance gun_damage (bool with_ammo=true) const
 Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods. More...
 
int gun_dispersion (bool with_ammo=true, bool with_scaling=true) const
 Summed dispersion of a gun, including values from mods. More...
 
skill_id gun_skill () const
 The skill used to operate the gun. More...
 
gun_type_type gun_type () const
 Get the type of a ranged weapon (e.g. More...
 
std::map< gunmod_location, int > get_mod_locations () const
 Get mod locations, including those added by other mods. More...
 
int get_free_mod_locations (const gunmod_location &location) const
 Number of mods that can still be installed into the given mod location, for non-guns it always returns 0. More...
 
bool is_firearm () const
 Does it require gunsmithing tools to repair. More...
 
int get_reload_time () const
 Returns the reload time of the gun. More...
 
Vehicle parts
int engine_displacement () const
 for combustion engines the displacement (cc) More...
 
- Public Member Functions inherited from visitable< item >
VisitResponse visit_items (const std::function< VisitResponse(item *, item *)> &func)
 Traverses this object and any child items contained using a visitor pattern. More...
 
VisitResponse visit_items (const std::function< VisitResponse(const item *, const item *)> &func) const
 
VisitResponse visit_items (const std::function< VisitResponse(item *)> &func)
 Lightweight version which provides only the current node. More...
 
VisitResponse visit_items (const std::function< VisitResponse(const item *)> &func) const
 
itemfind_parent (const item &it)
 Determine the immediate parent container (if any) for an item. More...
 
const itemfind_parent (const item &it) const
 
std::vector< item * > parents (const item &it)
 Returns vector of parent containers (if any) starting with the innermost. More...
 
std::vector< const item * > parents (const item &it) const
 
bool has_item (const item &it) const
 Returns true if this visitable instance contains the item. More...
 
bool has_item_with (const std::function< bool(const item &)> &filter) const
 Returns true if any item (including those within a container) matches the filter. More...
 
bool has_quality (const quality_id &qual, int level=1, int qty=1) const
 Returns true if instance has amount (or more) items of at least quality level. More...
 
int max_quality (const quality_id &qual) const
 Return maximum tool quality level provided by instance or INT_MIN if not found. More...
 
int charges_of (const itype_id &what, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >, std::function< void(int)> visitor=nullptr) const
 Count maximum available charges from this instance and any contained items. More...
 
int amount_of (const itype_id &what, bool pseudo=true, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >) const
 Count items matching id including both this instance and any contained items. More...
 
bool has_amount (const itype_id &what, int qty, bool pseudo=true, const std::function< bool(const item &)> &filter=return_true< item >) const
 Check instance provides at least qty of an item (. More...
 
std::vector< item * > items_with (const std::function< bool(const item &)> &filter)
 Returns all items (including those within a container) matching the filter. More...
 
std::vector< const item * > items_with (const std::function< bool(const item &)> &filter) const
 
std::list< itemremove_items_with (const std::function< bool(const item &)> &filter, int count=INT_MAX)
 Removes items contained by this instance which match the filter. More...
 
item remove_item (item &it)
 Removes and returns the item which must be contained by this instance. More...
 

Static Public Member Functions

static item make_corpse (const mtype_id &mt=string_id< mtype >::NULL_ID(), time_point turn=calendar::turn, const std::string &name="", int upgrade_time=-1)
 Make a corpse of the given monster type. More...
 

Bionics / CBMs

Functions specific to CBMs

enum class  sizing {
  human_sized_human_char = 0 , big_sized_human_char , small_sized_human_char , big_sized_big_char ,
  human_sized_big_char , small_sized_big_char , small_sized_small_char , human_sized_small_char ,
  big_sized_small_char , not_wearable
}
 
static const int INFINITE_CHARGES = INT_MAX
 
const itypetype
 
item_contents contents
 
std::list< itemcomponents
 
std::set< fault_idfaults
 What faults (if any) currently apply to this item. More...
 
FlagsSetType item_tags
 
int charges
 
units::energy energy
 
int recipe_charges = 1
 
int burnt = 0
 
int poison = 0
 
int frequency = 0
 
snippet_id snip_id = snippet_id::NULL_ID()
 
int irradiation = 0
 
int item_counter = 0
 
int mission_id = -1
 
int player_id = -1
 
bool encumbrance_update_ = false
 
char invlet = 0
 
bool active = false
 
safe_reference< Characteractivated_by
 
bool is_favorite = false
 
pimpl< item_drop_tokendrop_token
 Two items are dropped in same "batch" if they have identical drop tokens Ideally, this would be stored outside item class. More...
 
safe_reference_anchor anchor
 
const itypecurammo = nullptr
 
std::map< std::string, std::string > item_vars
 
const mtypecorpse = nullptr
 
std::string corpse_name
 
std::set< matec_idtechniques
 
cata::value_ptr< craft_datacraft_data_
 
cata::value_ptr< relicrelic_data
 
time_duration rot = 0_turns
 Accumulated rot, expressed as time the item has been in standard temperature. More...
 
time_point last_rot_check = calendar::turn_zero
 Time when the rot calculation was last performed. More...
 
time_point bday
 The time the item was created. More...
 
faction_id owner = faction_id::NULL_ID()
 
faction_id old_owner = faction_id::NULL_ID()
 
int damage_ = 0
 
light_emission light = nolight
 
bool is_upgrade () const
 Whether the CBM is an upgrade to another bionic module. More...
 
bool has_use () const
 Returns true if the item has any use function. More...
 
const use_functionget_use (const std::string &use_name) const
 Returns the pointer to use_function with name use_name assigned to the type of this item or any of its contents. More...
 
itemget_usable_item (const std::string &use_name)
 Checks this item and its contents (recursively) for types that have use_function with type use_name. More...
 
int units_remaining (const Character &ch, int limit=INT_MAX) const
 How many units (ammo or charges) are remaining? More...
 
bool units_sufficient (const Character &ch, int qty=-1) const
 Check if item has sufficient units (ammo or charges) remaining. More...
 
std::string get_corpse_name ()
 Returns name of deceased being if it had any or empty string if not. More...
 
bool has_label () const
 Returns true if item has "item_label" itemvar. More...
 
std::string label (unsigned int quantity=0) const
 Returns label from "item_label" itemvar and quantity. More...
 
bool has_infinite_charges () const
 
skill_id contextualize_skill (const skill_id &id) const
 Puts the skill in context of the item. More...
 
bool release_monster (const tripoint &target, int radius=0)
 
int contain_monster (const tripoint &target)
 
time_duration age () const
 
void set_age (const time_duration &age)
 
void legacy_fast_forward_time ()
 
time_point birthday () const
 
void set_birthday (const time_point &bday)
 
void handle_pickup_ownership (Character &c)
 
int get_gun_ups_drain () const
 
void validate_ownership () const
 
void set_old_owner (const faction_id &temp_owner)
 
void remove_old_owner () const
 
void set_owner (const faction_id &new_owner)
 
void set_owner (const Character &c)
 
void remove_owner () const
 
faction_id get_owner () const
 
faction_id get_old_owner () const
 
bool is_owned_by (const Character &c, bool available_to_take=false) const
 
bool is_old_owner (const Character &c, bool available_to_take=false) const
 
std::string get_owner_name () const
 
int get_min_str () const
 
const cata::value_ptr< islot_comestible > & get_comestible () const
 
const recipeget_making () const
 Get the stored recipe for in progress crafts. More...
 
int get_next_failure_point () const
 Get the failure point stored in this item. More...
 
void set_next_failure_point (const player &crafter)
 Calculates and sets the next failure point for an in progress craft. More...
 
bool handle_craft_failure (player &crafter)
 Handle failure during crafting. More...
 
requirement_data get_continue_reqs () const
 Returns requirement data representing what is needed to resume work on an in progress craft. More...
 
void inherit_flags (const item &parent, const recipe &making)
 Inherit applicable flags from the given parent item. More...
 
void inherit_flags (const std::list< item > &parents, const recipe &making)
 Inherit applicable flags from the given list of parent items. More...
 
void set_tools_to_continue (bool value)
 
bool has_tools_to_continue () const
 
void set_cached_tool_selections (const std::vector< comp_selection< tool_comp > > &selections)
 
const std::vector< comp_selection< tool_comp > > & get_cached_tool_selections () const
 
const std::vector< enchantment > & get_enchantments () const
 
double bonus_from_enchantments (const Character &owner, double base, enchant_vals::mod value, bool round=false) const
 Calculate bonus from enchantments that affect this item only. More...
 
double bonus_from_enchantments_wielded (double base, enchant_vals::mod value, bool round=false) const
 Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantments' conditions are satisfied. More...
 
const std::vector< relic_recharge > & get_relic_recharge_scheme () const
 
sizing get_sizing (const Character &, bool) const
 
void set_favorite (bool favorite)
 
bool has_clothing_mod () const
 
float get_clothing_mod_val (clothing_mod_type type) const
 
void update_clothing_mod_val ()
 
static std::string nname (const itype_id &id, unsigned int quantity=1)
 Returns the translated item name for the item with given id. More...
 
static bool count_by_charges (const itype_id &id)
 Whether the item is counted by charges, this is a static wrapper around count_by_charges, that does not need an items instance. More...
 
bool use_amount_internal (const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
 
const use_functionget_use_internal (const std::string &use_name) const
 
bool process_internal (player *carrier, const tripoint &pos, bool activate, bool seals, temperature_flag flag, const weather_manager &weather_generator)
 
bool is_reloadable_helper (const itype_id &ammo, bool now) const
 Helper for checking reloadability. More...
 
bool process_corpse (player *carrier, const tripoint &pos)
 
bool process_wet (player *carrier, const tripoint &pos)
 
bool process_litcig (player *carrier, const tripoint &pos)
 
bool process_extinguish (player *carrier, const tripoint &pos)
 
bool process_fake_smoke (player *carrier, const tripoint &pos)
 
bool process_fake_mill (player *carrier, const tripoint &pos)
 
bool process_cable (player *carrier, const tripoint &pos)
 
bool process_UPS (player *carrier, const tripoint &pos)
 
bool process_blackpowder_fouling (player *carrier)
 
bool process_tool (player *carrier, const tripoint &pos)
 

Additional Inherited Members

Detailed Description

Definition at line 210 of file item.h.

Member Typedef Documentation

◆ archive_type_tag

Definition at line 494 of file item.h.

◆ FlagsSetType

using item::FlagsSetType = cata::flat_set<std::string>

Definition at line 213 of file item.h.

Member Enumeration Documentation

◆ sizing

enum class item::sizing
strong
Enumerator
human_sized_human_char 
big_sized_human_char 
small_sized_human_char 
big_sized_big_char 
human_sized_big_char 
small_sized_big_char 
small_sized_small_char 
human_sized_small_char 
big_sized_small_char 
not_wearable 

Definition at line 2130 of file item.h.

2130 {
2131 human_sized_human_char = 0,
2132 big_sized_human_char,
2133 small_sized_human_char,
2134 big_sized_big_char,
2135 human_sized_big_char,
2136 small_sized_big_char,
2137 small_sized_small_char,
2138 human_sized_small_char,
2139 big_sized_small_char,
2140 not_wearable
2141 };

Constructor & Destructor Documentation

◆ item() [1/11]

item::item ( )

Definition at line 365 of file item.cpp.

366{
367 type = nullitem();
368 charges = 0;
369}
time_point bday
The time the item was created.
Definition: item.h:2231
int charges
Definition: item.h:2203
const itype * type
Definition: item.h:2164
static const itype * nullitem()
Definition: item.cpp:316
const time_point & start_of_cataclysm
Definition: calendar.cpp:33

References charges, nullitem(), and type.

Referenced by add_rain_to_container(), ammo_set(), vehicle_part::deserialize(), io(), item(), and split().

◆ item() [2/11]

item::item ( item &&  )
default

◆ item() [3/11]

item::item ( const item )
default

◆ item() [4/11]

item::item ( const itype_id id,
time_point  turn = calendar::turn,
int  qty = -1 
)
explicit

Definition at line 431 of file item.cpp.

432 : item( & * id, turn, qty ) {}
item()
Definition: item.cpp:365
time_point turn
Definition: calendar.cpp:36

◆ item() [5/11]

item::item ( const itype type,
time_point  turn = calendar::turn,
int  qty = -1 
)
explicit

Definition at line 371 of file item.cpp.

371 : type( type ), bday( turn )
372{
373 corpse = has_flag( flag_CORPSE ) ? &mtype_id::NULL_ID().obj() : nullptr;
375
376 if( qty >= 0 ) {
377 charges = qty;
378 } else {
379 if( type->tool && type->tool->rand_charges.size() > 1 ) {
380 const int charge_roll = rng( 1, type->tool->rand_charges.size() - 1 );
381 charges = rng( type->tool->rand_charges[charge_roll - 1], type->tool->rand_charges[charge_roll] );
382 } else {
384 }
385 }
386
388 itype_id nanofab_recipe = item_group::item_from( item_group_id( "nanofab_recipes" ) ).typeId();
389 set_var( "NANOFAB_ITEM_ID", nanofab_recipe.str() );
390 }
391
392 if( type->gun ) {
393 for( const itype_id &mod : type->gun->built_in_mods ) {
394 item it( mod, turn, qty );
395 it.set_flag( "IRREMOVABLE" );
396 put_in( it );
397 }
398 for( const itype_id &mod : type->gun->default_mods ) {
399 put_in( item( mod, turn, qty ) );
400 }
401
402 } else if( type->magazine ) {
403 if( type->magazine->count > 0 ) {
404 put_in( item( type->magazine->default_ammo, calendar::turn, type->magazine->count ) );
405 }
406
407 } else if( goes_bad() ) {
408 active = true;
410
411 } else if( type->tool ) {
412 if( ammo_remaining() && !ammo_types().empty() ) {
414 }
415 }
416
417 if( ( type->gun || type->tool ) && !magazine_integral() ) {
418 set_var( "magazine_converted", 1 );
419 }
420
421 if( !type->snippet_category.empty() ) {
423 }
424
425 // item always has any relic properties from itype.
426 if( type->relic_data ) {
428 }
429}
units::quantity< V, B > rng(const units::quantity< V, B > &min, const units::quantity< V, B > &max)
Definition: artifact.cpp:32
Definition: item.h:211
int ammo_remaining() const
Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.
Definition: item.cpp:7387
bool active
Definition: item.h:2241
void put_in(const item &payload)
Puts the given item into this one, no checks are performed.
Definition: item.cpp:995
void set_var(const std::string &name, int value)
Definition: item.cpp:1000
item & ammo_set(const itype_id &ammo, int qty=-1)
Filter setting the ammo for this instance Any existing ammo is removed.
Definition: item.cpp:590
bool goes_bad() const
whether an item is perishable (can rot)
Definition: item.cpp:5498
const mtype * corpse
Definition: item.h:2176
snippet_id snip_id
Definition: item.h:2210
const itype_id & typeId() const
return the unique identifier of the items underlying type
Definition: item.cpp:8358
bool magazine_integral() const
Does item have an integral magazine (as opposed to allowing detachable magazines)
Definition: item.cpp:7665
bool has_flag(const std::string &flag) const
Definition: item.cpp:5303
itype_id ammo_default(bool conversion=true) const
Get default ammo used by item or a null id if item does not have a default ammo type.
Definition: item.cpp:7601
time_point last_rot_check
Time when the rot calculation was last performed.
Definition: item.h:2229
const std::set< ammotype > & ammo_types(bool conversion=true) const
Set of ammo types (ammunition_type) used by item.
Definition: item.cpp:7570
int item_counter
Definition: item.h:2212
cata::value_ptr< relic > relic_data
Definition: item.h:2201
snippet_id random_id_from_category(const std::string &cat) const
Returns the id of a random snippet out of the given category.
const T & obj() const
Returns the actual object this id refers to.
Definition: achievement.cpp:60
const std::string & str() const
Returns the identifier as plain std::string.
Definition: string_id.h:255
static const string_id< mtype > & NULL_ID()
Returns a null id whose string_id<T>::is_null() must always return true.
static const std::string flag_NANOFAB_TEMPLATE("NANOFAB_TEMPLATE")
static const std::string flag_CORPSE("CORPSE")
item item_from(const item_group_id &group_id, const time_point &birthday)
Returns a random item from the item group, handles packaged food by putting it into its container and...
Definition: item_group.cpp:589
std::string snippet_category
Definition: itype.h:907
cata::value_ptr< islot_gun > gun
Definition: itype.h:859
cata::value_ptr< islot_tool > tool
Definition: itype.h:849
int charges_default() const
Definition: itype.cpp:98
cata::value_ptr< relic > relic_data
Definition: itype.h:867
cata::value_ptr< islot_magazine > magazine
Definition: itype.h:861
int countdown_interval
Default countdown interval (if any) for item.
Definition: itype.h:953
snippet_library SNIPPET
string_id< Item_group > item_group_id
Definition: type_id.h:77

References active, ammo_default(), ammo_remaining(), ammo_set(), ammo_types(), bday, charges, itype::charges_default(), corpse, itype::countdown_interval, flag_CORPSE(), flag_NANOFAB_TEMPLATE(), goes_bad(), itype::gun, has_flag(), item(), item_counter, item_group::item_from(), last_rot_check, itype::magazine, magazine_integral(), string_id< mtype >::NULL_ID(), string_id< T >::obj(), put_in(), snippet_library::random_id_from_category(), relic_data, itype::relic_data, rng(), set_flag(), set_var(), snip_id, SNIPPET, itype::snippet_category, string_id< T >::str(), itype::tool, calendar::turn, type, and typeId().

◆ item() [6/11]

item::item ( const itype_id id,
time_point  turn,
default_charges_tag  tag 
)

Definition at line 437 of file item.cpp.

438 : item( & * id, turn, tag ) {}

◆ item() [7/11]

item::item ( const itype type,
time_point  turn,
default_charges_tag   
)

Definition at line 434 of file item.cpp.

435 : item( type, turn, type->charges_default() ) {}

◆ item() [8/11]

item::item ( const itype_id id,
time_point  turn,
solitary_tag  tag 
)

Definition at line 443 of file item.cpp.

444 : item( & * id, turn, tag ) {}

◆ item() [9/11]

item::item ( const itype type,
time_point  turn,
solitary_tag   
)

Definition at line 440 of file item.cpp.

441 : item( type, turn, type->count_by_charges() ? 1 : -1 ) {}
bool count_by_charges() const
Definition: itype.cpp:93

◆ item() [10/11]

item::item ( const recipe rec,
int  qty,
std::list< item items,
std::vector< item_comp selections 
)

For constructing in-progress crafts.

Definition at line 464 of file item.cpp.

465 : item( "craft", calendar::turn, qty )
466{
467 craft_data_ = cata::make_value<craft_data>();
468 craft_data_->making = rec;
469 components = items;
470 craft_data_->comps_used = selections;
471
472 if( is_food() ) {
473 active = true;
475 if( goes_bad() ) {
476 const item *most_rotten = get_most_rotten_component( *this );
477 if( most_rotten ) {
478 set_relative_rot( most_rotten->get_relative_rot() );
479 }
480 }
481 }
482
483 for( item &component : components ) {
484 for( const std::string &f : component.item_tags ) {
485 if( json_flag::get( f ).craft_inherit() ) {
486 set_flag( f );
487 }
488 }
489 for( const std::string &f : component.type->get_flags() ) {
490 if( json_flag::get( f ).craft_inherit() ) {
491 set_flag( f );
492 }
493 }
494 }
495 // this extra section is so that in-progress crafts will correctly display expected flags.
496 for( const std::string &flag : rec->flags_to_delete ) {
497 unset_flag( flag );
498 }
499}
cata::value_ptr< craft_data > craft_data_
Definition: item.h:2198
std::list< item > components
Definition: item.h:2166
bool is_food() const
Definition: item.cpp:6592
item & set_flag(const std::string &flag)
Idempotent filter setting an item specific flag.
Definition: item.cpp:5332
item & unset_flag(const std::string &flag)
Idempotent filter removing an item specific flag.
Definition: item.cpp:5338
void set_relative_rot(double val)
Set current item rot relative to shelf life (no-op if item does not spoil)
Definition: item.cpp:5539
double get_relative_rot() const
Get rot value relative to shelf life (or 0 if item does not spoil)
Definition: item.cpp:5531
static const json_flag & get(const std::string &id)
Fetches flag definition (or null flag if not found)
Definition: flag.cpp:70
std::set< std::string > flags_to_delete
Definition: recipe.h:115
static const item * get_most_rotten_component(const item &craft)
Definition: item.cpp:451
itype_id type
Definition: requirements.h:58
const FlagsSetType & get_flags() const
Definition: itype.cpp:156

References active, bday, components, craft_data_, recipe::flags_to_delete, json_flag::get(), itype::get_flags(), get_most_rotten_component(), get_relative_rot(), goes_bad(), is_food(), last_rot_check, set_flag(), set_relative_rot(), component::type, and unset_flag().

◆ item() [11/11]

template<typename... Args>
item::item ( const std::string &  itype,
Args &&...  args 
)
inline

Definition at line 241 of file item.h.

241 :
242 item( itype_id( itype ), std::forward<Args>( args )... )
243 {}
Definition: itype.h:836

◆ ~item()

item::~item ( )
default

Member Function Documentation

◆ acid_resist()

int item::acid_resist ( bool  to_self = false,
int  base_env_resist = 0 
) const

Resistance against different damage types (damage_type).

Larger values means more resistance are thereby better, but there is no absolute value to compare them to. The values can be interpreted as chance (one_in) of damaging the item when exposed to the type of damage.

Parameters
to_selfIf this is true, it returns item's own resistance, not one it gives to wearer.
base_env_resistWill override the base environmental resistance (to allow hypothetical calculations for gas masks).

Definition at line 6127 of file item.cpp.

6128{
6129 if( to_self ) {
6130 // Currently no items are damaged by acid
6131 return INT_MAX;
6132 }
6133
6134 float resist = 0.0;
6136 if( is_null() ) {
6137 return 0.0;
6138 }
6139
6140 const std::vector<const material_type *> mat_types = made_of_types();
6141 if( !mat_types.empty() ) {
6142 // Not sure why cut and bash get an armor thickness bonus but acid doesn't,
6143 // but such is the way of the code.
6144
6145 for( const material_type *mat : mat_types ) {
6146 resist += mat->acid_resist();
6147 }
6148 // Average based on number of materials.
6149 resist /= mat_types.size();
6150 }
6151
6152 const int env = get_env_resist( base_env_resist );
6153 if( env < 10 ) {
6154 // Low env protection means it doesn't prevent acid seeping in.
6155 resist *= env / 10.0f;
6156 }
6157
6158 return std::lround( resist + mod );
6159}
float get_clothing_mod_val(clothing_mod_type type) const
Definition: item.cpp:10143
bool is_null() const
Definition: item.cpp:732
std::vector< const material_type * > made_of_types() const
Same as made_of(), but returns the material_type directly.
Definition: item.cpp:6426
int get_env_resist(int override_base_resist=0) const
Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides whe...
Definition: item.cpp:5763
@ clothing_mod_type_acid
Definition: clothing_mod.h:17

References clothing_mod_type_acid, get_clothing_mod_val(), get_env_resist(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ activate()

item & item::activate ( )

Filter converting instance to active state.

Definition at line 557 of file item.cpp.

558{
559 if( active ) {
560 return *this; // no-op
561 }
562
563 if( type->countdown_interval > 0 ) {
565 }
566
567 active = true;
568
569 return *this;
570}

References active, itype::countdown_interval, item_counter, and type.

Referenced by iuse::cable_attach(), make_gun_projectile(), process(), and process_internal().

◆ actualize_rot()

bool item::actualize_rot ( const tripoint pnt,
temperature_flag  temperature,
const weather_manager weather 
)

Whether the item has to be removed as it has rotten away completely.

May change the item as it calls process_rot()

Parameters
pntThe position of the item on the current map.
temperatureFlag for special locations that affect temperature.
weatherWeather manager to supply temperature.
Returns
true if the item has rotten away and should be removed, false otherwise.

Definition at line 8804 of file item.cpp.

8806{
8807 if( goes_bad() ) {
8808 return process_rot( false, pnt, nullptr, temperature, weather );
8809 } else if( type->container && type->container->preserves ) {
8810 // Containers like tin cans preserves all items inside, they do not rot at all.
8811 return false;
8812 } else if( type->container && type->container->seals ) {
8813 // Items inside rot but do not vanish as the container seals them in.
8814 for( item *c : contents.all_items_top() ) {
8815 if( c->goes_bad() ) {
8816 c->process_rot( true, pnt, nullptr, temperature, weather );
8817 }
8818 }
8819 return false;
8820 } else {
8821 std::vector<item *> removed_items;
8822 // Check and remove rotten contents, but always keep the container.
8823 for( item *it : contents.all_items_top() ) {
8824 if( it->actualize_rot( pnt, temperature, weather ) ) {
8825 removed_items.push_back( it );
8826 }
8827 }
8828 for( item *it : removed_items ) {
8829 remove_item( *it );
8830 }
8831
8832 return false;
8833 }
8834}
std::list< item * > all_items_top()
returns a list of pointers to all top-level items
item_contents contents
Definition: item.h:2165
bool process_rot(const tripoint &pos)
Update temperature for things like food Update rot for things that perish All items that rot also hav...
Definition: item.cpp:8951
item remove_item(item &it)
Removes and returns the item which must be contained by this instance.
Definition: visitable.cpp:564
constexpr double c
Definition: magic.cpp:1032
quantity< int, temperature_in_millidegree_celsius_tag > temperature
cata::value_ptr< islot_container > container
Slots for various item type properties.
Definition: itype.h:848

References item_contents::all_items_top(), c, itype::container, contents, goes_bad(), process_rot(), visitable< item >::remove_item(), and type.

◆ add_technique()

void item::add_technique ( const matec_id tech)

Add the given technique to the item specific techniques.

Note that other items of the same type are not affected by this.

Definition at line 5444 of file item.cpp.

5445{
5446 techniques.insert( tech );
5447}
std::set< matec_id > techniques
Definition: item.h:2178

References techniques.

Referenced by mdeath::jabberwock().

◆ age()

◆ allow_crafting_component()

bool item::allow_crafting_component ( ) const

Permits filthy components, should only be used as a helper in creating filters.

Definition at line 8538 of file item.cpp.

8539{
8540 if( is_toolmod() && is_irremovable() ) {
8541 return false;
8542 }
8543
8544 // vehicle batteries are implemented as magazines of charge
8545 if( is_magazine() && ammo_types().count( ammo_battery ) ) {
8546 return true;
8547 }
8548
8549 // fixes #18886 - turret installation may require items with irremovable mods
8550 if( is_gun() ) {
8551 bool valid = true;
8552 visit_items( [&]( const item * it ) {
8553 if( this == it ) {
8554 return VisitResponse::NEXT;
8555 }
8556 if( !( it->is_magazine() || ( it->is_gunmod() && it->is_irremovable() ) ) ) {
8557 valid = false;
8558 return VisitResponse::ABORT;
8559 }
8560 return VisitResponse::NEXT;
8561 } );
8562 return valid;
8563 }
8564
8565 return contents.empty();
8566}
bool empty() const
int count() const
If count_by_charges(), returns charges, otherwise 1.
Definition: item.cpp:6010
bool is_irremovable() const
Definition: item.cpp:6775
bool is_gun() const
Can this item be used to perform a ranged attack?
Definition: item.cpp:6517
bool is_toolmod() const
Definition: item.cpp:6765
bool is_gunmod() const
Definition: item.cpp:6547
bool is_magazine() const
Definition: item.cpp:6557
VisitResponse visit_items(const std::function< VisitResponse(item *, item *)> &func)
Traverses this object and any child items contained using a visitor pattern.
Definition: visitable.cpp:422
static const ammotype ammo_battery("battery")

References ammo_battery, ammo_types(), contents, count(), item_contents::empty(), is_gun(), is_gunmod(), is_irremovable(), is_magazine(), is_toolmod(), NEXT, and visitable< item >::visit_items().

◆ already_used_by_player()

bool item::already_used_by_player ( const player p) const

Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific player.

Definition at line 8853 of file item.cpp.

8854{
8855 const auto it = item_vars.find( USED_BY_IDS );
8856 if( it == item_vars.end() ) {
8857 return false;
8858 }
8859 // USED_BY_IDS always starts *and* ends with a ';', the search string
8860 // ';<id>;' matches at most one part of USED_BY_IDS, and only when exactly that
8861 // id has been added.
8862 const std::string needle = string_format( ";%d;", p.getID().get_value() );
8863 return it->second.find( needle ) != std::string::npos;
8864}
character_id getID() const
Definition: character.cpp:491
int get_value() const
Definition: character_id.h:23
std::map< std::string, std::string > item_vars
Definition: item.h:2175
static const std::string USED_BY_IDS("USED_BY_IDS")
std::string string_format(std::string_view format, Args &&...args)
Simple wrapper over string_formatter::parse.

References character_id::get_value(), Character::getID(), item_vars, string_format(), and USED_BY_IDS().

Referenced by tname(), and reveal_map_actor::use().

◆ ammo_capacity() [1/2]

◆ ammo_capacity() [2/2]

int item::ammo_capacity ( bool  potential_capacity) const
Parameters
potential_capacitywhether to try a default magazine if necessary

Definition at line 7419 of file item.cpp.

7420{
7421 int res = 0;
7422
7423 const item *mag = magazine_current();
7424 if( mag ) {
7425 return mag->ammo_capacity();
7426 }
7427
7428 if( is_tool() ) {
7429 res = type->tool->max_charges;
7430 if( res == 0 && magazine_default() && potential_capacity ) {
7431 res = magazine_default()->magazine->capacity;
7432 }
7433 for( const item *e : toolmods() ) {
7434 res *= e->type->mod->capacity_multiplier;
7435 }
7436 }
7437
7438 if( is_gun() ) {
7439 res = type->gun->clip;
7440 for( const item *e : gunmods() ) {
7441 res *= e->type->mod->capacity_multiplier;
7442 }
7443 }
7444
7445 if( is_magazine() ) {
7446 res = type->magazine->capacity;
7447 }
7448
7449 if( is_bandolier() ) {
7450 return dynamic_cast<const bandolier_actor *>
7451 ( type->get_use( "bandolier" )->get_actor_ptr() )->capacity;
7452 }
7453
7454 return res;
7455}
Store ammo and later reload using it.
Definition: iuse_actor.h:884
std::vector< item * > toolmods()
Returns all toolmods currently attached to this item (always empty if item not a tool)
Definition: item.cpp:5449
bool is_tool() const
Definition: item.cpp:6958
itype_id magazine_default(bool conversion=true) const
Get the default magazine type (if any) for the current effective ammo type.
Definition: item.cpp:7680
bool is_bandolier() const
Definition: item.cpp:6572
item * magazine_current()
Currently loaded magazine (if any)
Definition: item.cpp:7727
std::vector< item * > gunmods()
Returns all gunmods currently attached to this item (always empty if item not a gun)
Definition: item.cpp:7740
const use_function * get_use(const std::string &iuse_name) const
Definition: itype.cpp:166
iuse_actor * get_actor_ptr()
Definition: iuse.h:315

References ammo_capacity(), use_function::get_actor_ptr(), itype::get_use(), itype::gun, gunmods(), is_bandolier(), is_gun(), is_magazine(), is_tool(), itype::magazine, magazine_current(), magazine_default(), itype::tool, toolmods(), and type.

◆ ammo_consume()

int item::ammo_consume ( int  qty,
const tripoint pos 
)

Consume ammo (if available) and return the amount of ammo that was consumed.

Parameters
qtymaximum amount of ammo that should be consumed
poscurrent location of item, used for ejecting magazines and similar effects
Returns
amount of ammo consumed which will be between 0 and qty

Definition at line 7485 of file item.cpp.

7486{
7487 if( qty < 0 ) {
7488 debugmsg( "Cannot consume negative quantity of ammo for %s", tname() );
7489 return 0;
7490 }
7491
7492 item *mag = magazine_current();
7493 if( mag ) {
7494 const int res = mag->ammo_consume( qty, pos );
7495 if( res && ammo_remaining() == 0 ) {
7496 if( mag->has_flag( flag_MAG_DESTROY ) ) {
7497 remove_item( *mag );
7498 } else if( mag->has_flag( flag_MAG_EJECT ) ) {
7499 get_map().add_item( pos, *mag );
7500 remove_item( *mag );
7501 }
7502 }
7503 return res;
7504 }
7505
7506 if( is_magazine() ) {
7507 int need = qty;
7508 while( !contents.empty() ) {
7509 item &e = contents.front();
7510 if( need >= e.charges ) {
7511 need -= e.charges;
7513 } else {
7514 e.charges -= need;
7515 need = 0;
7516 break;
7517 }
7518 }
7519 return qty - need;
7520
7521 } else if( is_tool() || is_gun() ) {
7522 qty = std::min( qty, charges );
7524 avatar &you = get_avatar();
7527 }
7528 charges -= qty;
7529 if( charges == 0 ) {
7530 curammo = nullptr;
7531 }
7532 return qty;
7533 }
7534
7535 return 0;
7536}
avatar & get_avatar()
Definition: avatar.cpp:104
void mod_power_level(const units::energy &npower)
Definition: character.cpp:1919
units::energy get_power_level() const
Definition: character.cpp:1899
Definition: avatar.h:55
item & front()
this is an artifact of the previous code using front() everywhere for contents.
std::string tname(unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
Return the (translated) item name.
Definition: item.cpp:4554
int ammo_consume(int qty, const tripoint &pos)
Consume ammo (if available) and return the amount of ammo that was consumed.
Definition: item.cpp:7485
const itype * curammo
Definition: item.h:2174
item & add_item(const tripoint &p, item new_item)
Place an item on the map, despite the parameter name, this is not necessarily a new item.
Definition: map.cpp:4432
#define debugmsg(...)
Debug message of level DL::Error and class DC::DebugMsg, also includes the source file name and line,...
Definition: debug.h:74
static const std::string flag_USES_BIONIC_POWER("USES_BIONIC_POWER")
static const std::string flag_MAG_DESTROY("MAG_DESTROY")
static const std::string flag_MAG_EJECT("MAG_EJECT")
map & get_map()
Definition: map.cpp:147
constexpr value_type to_kilojoule(const quantity< value_type, energy_in_joule_tag > &v)
Definition: units_energy.h:46
constexpr quantity< value_type, energy_in_joule_tag > from_kilojoule(const value_type v)
Definition: units_energy.h:32

References map::add_item(), ammo_consume(), ammo_remaining(), charges, contents, curammo, debugmsg, item_contents::empty(), flag_MAG_DESTROY(), flag_MAG_EJECT(), flag_USES_BIONIC_POWER(), units::from_kilojoule(), item_contents::front(), get_avatar(), get_map(), Character::get_power_level(), has_flag(), is_gun(), is_magazine(), is_tool(), magazine_current(), Character::mod_power_level(), visitable< item >::remove_item(), tname(), and units::to_kilojoule().

Referenced by ammo_consume(), vehicle_part::ammo_consume(), Character::consume_charges(), iuse::einktabletpc(), ranged::fire_gun(), activity_handlers::game_do_turn(), iuse::gasmask(), iuse::multicooker(), iuse::note_bionics(), activity_handlers::oxytorch_do_turn(), npc::pretend_fire(), process_tool(), reload(), activity_handlers::repair_item_finish(), toolweapon_on(), and activity_handlers::vibe_do_turn().

◆ ammo_current()

itype_id item::ammo_current ( ) const

Specific ammo type, returns "null" if item is neither ammo nor loaded with any.

Definition at line 7564 of file item.cpp.

7565{
7566 const itype *ammo = ammo_data();
7567 return ammo ? ammo->get_id() : itype_id::NULL_ID();
7568}
const itype * ammo_data() const
Specific ammo data, returns nullptr if item is neither ammo nor loaded with any.
Definition: item.cpp:7538
const itype_id & get_id() const
Definition: itype.cpp:88

References ammo_data(), itype::get_id(), and string_id< itype >::NULL_ID().

Referenced by vehicle_part::ammo_current(), turret_data::ammo_options(), npc::confident_gun_mode_range(), display_name(), aim_activity_actor::do_turn(), ranged::fire_gun(), avatar_action::fire_wielded_weapon(), get_remaining_capacity_for_liquid(), gun_noise(), npc_ai::gun_value(), ideal_ranged_dps(), is_reloadable_helper(), make_gun_projectile(), parse_tags(), remove_ammo(), activity_handlers::repair_item_finish(), stacks_with(), avatar_funcs::unload_item(), iuse_transform::use(), and weight().

◆ ammo_data()

const itype * item::ammo_data ( ) const

Specific ammo data, returns nullptr if item is neither ammo nor loaded with any.

Definition at line 7538 of file item.cpp.

7539{
7540 const item *mag = magazine_current();
7541 if( mag ) {
7542 return mag->ammo_data();
7543 }
7544
7545 if( is_ammo() ) {
7546 return type;
7547 }
7548
7549 if( is_magazine() ) {
7550 return !contents.empty() ? contents.front().ammo_data() : nullptr;
7551 }
7552
7553 auto mods = is_gun() ? gunmods() : toolmods();
7554 for( const item *e : mods ) {
7555 if( !e->type->mod->ammo_modifier.empty() && e->ammo_current() &&
7556 e->ammo_current().is_valid() ) {
7557 return &*e->ammo_current();
7558 }
7559 }
7560
7561 return curammo;
7562}
bool is_ammo() const
Definition: item.cpp:6582

References ammo_data(), contents, curammo, item_contents::empty(), item_contents::front(), gunmods(), is_ammo(), is_gun(), is_magazine(), magazine_current(), toolmods(), and type.

Referenced by ammo_current(), ammo_data(), turret_data::ammo_data(), ammo_effects(), ammo_info(), cycle_action(), Character::deactivate_bionic(), avatar_action::fire_wielded_weapon(), gun_damage(), gun_dispersion(), gun_info(), gun_noise(), gun_range(), gun_recoil(), ranged::handle_gun_damage(), is_reloadable_helper(), make_gun_projectile(), Item_modifier::modify(), price(), character_funcs::select_ammo(), target_ui::update_ammo_range_from_gun_mode(), weapon_inventory_preset::weapon_inventory_preset(), and weight().

◆ ammo_default()

itype_id item::ammo_default ( bool  conversion = true) const

Get default ammo used by item or a null id if item does not have a default ammo type.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
itype_id::NULL_ID() if item does not use a specific ammo type (and is consequently not reloadable)

Definition at line 7601 of file item.cpp.

7602{
7603 if( is_magazine() ) {
7604 return type->magazine->default_ammo;
7605 }
7606
7607 const std::set<ammotype> &atypes = ammo_types( conversion );
7608 if( !atypes.empty() ) {
7609 itype_id res = ammotype( *atypes.begin() )->default_ammotype();
7610 if( !res.is_empty() ) {
7611 return res;
7612 }
7613 }
7614 return itype_id::NULL_ID();
7615}
const itype_id & default_ammotype() const
Definition: ammo.h:21
bool is_empty() const
Returns whether this id is empty.
Definition: string_id.h:298
string_id< ammunition_type > ammotype
Definition: type_id.h:12

References ammo_types(), ammunition_type::default_ammotype(), string_id< T >::is_empty(), is_magazine(), itype::magazine, string_id< itype >::NULL_ID(), and type.

Referenced by basecamp::add_resource(), turret_data::ammo_current(), crafting::complete_disassemble(), game::dump_stats(), npc::enough_time_to_reload(), inventory::form_from_map(), gun_info(), npc_ai::gun_value(), ideal_ranged_dps(), item(), Item_modifier::modify(), relic_funcs::process_recharge_entry(), gun_actor::shoot(), starting_inv(), iexamine::use_furn_fake_item(), npc_ai::wielded_value(), and debug_menu::wishitem().

◆ ammo_effects()

std::set< ammo_effect_str_id > item::ammo_effects ( bool  with_ammo = true) const

Get ammo effects for item optionally inclusive of any resulting from the loaded ammo.

Definition at line 7633 of file item.cpp.

7634{
7635 if( !is_gun() ) {
7636 return std::set<ammo_effect_str_id>();
7637 }
7638
7639 std::set<ammo_effect_str_id> res = type->gun->ammo_effects;
7640 if( with_ammo && ammo_data() ) {
7641 res.insert( ammo_data()->ammo->ammo_effects.begin(), ammo_data()->ammo->ammo_effects.end() );
7642 }
7643
7644 for( const item *mod : gunmods() ) {
7645 res.insert( mod->type->gunmod->ammo_effects.begin(), mod->type->gunmod->ammo_effects.end() );
7646 }
7647
7648 return res;
7649}

References ammo_data(), itype::gun, gunmods(), is_gun(), and type.

Referenced by turret_data::ammo_effects(), gun_noise(), ranged::handle_gun_damage(), and make_gun_projectile().

◆ ammo_info()

void item::ammo_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1904 of file item.cpp.

1906{
1907 if( is_gun() || !ammo_data() || !parts->test( iteminfo_parts::AMMO_REMAINING_OR_TYPES ) ) {
1908 return;
1909 }
1910
1911 const std::string space = " ";
1912 if( ammo_remaining() > 0 ) {
1913 info.emplace_back( "AMMO", _( "<bold>Ammunition</bold>: " ),
1914 ammo_data()->nname( ammo_remaining() ) );
1915 } else if( is_ammo() ) {
1916 info.emplace_back( "AMMO", _( "<bold>Ammunition type</bold>: " ), ammo_type()->name() );
1917 }
1918
1919 const islot_ammo &ammo = *ammo_data()->ammo;
1920 if( !ammo.damage.empty() || ammo.force_stat_display ) {
1921 bool has_flat_dmg = !ammo.damage.empty() && ammo.damage.damage_units.front().amount > 0;
1922 bool display_flat_dmg = parts->test( iteminfo_parts::AMMO_DAMAGE_VALUE );
1923 // TODO: Multiple units
1924 bool has_dmg_multiplier = ammo.damage.damage_units.front().damage_multiplier != 1.0;
1925 bool display_dmg_multiplier = parts->test( iteminfo_parts::AMMO_DAMAGE_PROPORTIONAL );
1926 bool didnt_print_dmg = false;
1927 if( has_flat_dmg && has_dmg_multiplier
1928 && has_dmg_multiplier && display_dmg_multiplier ) {
1929 info.emplace_back( "AMMO", _( "Damage: " ), "",
1931 info.emplace_back( "AMMO", "/", "",
1933 ammo.damage.damage_units.front().damage_multiplier );
1934 // Messy ifs...
1935 } else if( display_dmg_multiplier && ( has_dmg_multiplier || !has_flat_dmg ) ) {
1936 info.emplace_back( "AMMO", _( "Damage multiplier: " ), "",
1938 ammo.damage.damage_units.front().damage_multiplier );
1939 } else if( display_flat_dmg ) {
1940 info.emplace_back( "AMMO", _( "Damage: " ), "",
1942 } else {
1943 didnt_print_dmg = true;
1944 }
1945
1946 // Ugly, but handles edge cases better than mandatory space
1947 static const std::string no_space;
1948 const std::string &maybe_space = didnt_print_dmg ? no_space : space;
1949
1950 // TODO: Deduplicate with damage display
1951 bool has_flat_arpen = get_ranged_pierce( ammo ) != 0;
1952 bool display_flat_arpen = parts->test( iteminfo_parts::AMMO_DAMAGE_AP );
1953 bool has_armor_mult = get_ranged_armor_mult( ammo ) != 1.0;
1954 bool display_armor_mult = parts->test( iteminfo_parts::AMMO_DAMAGE_AP_PROPORTIONAL );
1955 if( has_flat_arpen && display_flat_arpen
1956 && has_armor_mult && display_armor_mult ) {
1957 info.emplace_back( "AMMO", maybe_space + _( "Armor-pierce: " ), "",
1959 info.emplace_back( "AMMO", "/", "",
1961 get_ranged_armor_mult( ammo ) );
1962 } else if( has_armor_mult && display_armor_mult ) {
1963 info.emplace_back( "AMMO", maybe_space + _( "Armor multiplier: " ), "",
1965 } else if( display_flat_arpen ) {
1966 info.emplace_back( "AMMO", maybe_space + _( "Armor-pierce: " ), get_ranged_pierce( ammo ) );
1967 }
1968 if( parts->test( iteminfo_parts::AMMO_DAMAGE_RANGE ) ) {
1969 info.emplace_back( "AMMO", _( "Range: " ), "", iteminfo::no_newline, ammo.shape
1970 ? static_cast<int>( ammo.shape->get_range() )
1971 : ammo.range );
1972 }
1974 info.emplace_back( "AMMO", space + _( "Dispersion: " ), "",
1976 }
1978 info.emplace_back( "AMMO", _( "Recoil: " ), "",
1980 }
1981 }
1982
1983 // TODO: De-hardcode. Have it imply a flag? Just include description_on_item in ammo_effect struct?
1984 std::vector<std::string> fx;
1985 if( ammo.shape &&
1986 parts->test( iteminfo_parts::AMMO_SHAPE ) ) {
1987 fx.emplace_back( string_format(
1988 _( "This ammo will produce effects with the following shape:\n<bold>%s</bold>" ),
1989 ammo.shape->get_description() ) );
1990 }
1991 if( ammo.ammo_effects.count( ammo_effect_RECYCLED ) &&
1993 fx.emplace_back( _( "This ammo has been <bad>hand-loaded</bad>." ) );
1994 }
1995 if( ammo.ammo_effects.count( ammo_effect_BLACKPOWDER ) &&
1997 fx.emplace_back(
1998 _( "This ammo has been loaded with <bad>blackpowder</bad>, and will quickly "
1999 "clog up most guns, and cause rust if the gun is not cleaned." ) );
2000 }
2001 if( ammo.ammo_effects.count( ammo_effect_NEVER_MISFIRES ) &&
2003 fx.emplace_back( _( "This ammo <good>never misfires</good>." ) );
2004 }
2005 if( ammo.ammo_effects.count( ammo_effect_INCENDIARY ) &&
2007 fx.emplace_back( _( "This ammo <neutral>starts fires</neutral>." ) );
2008 }
2009 if( !fx.empty() ) {
2011 for( const std::string &e : fx ) {
2012 info.emplace_back( "AMMO", e );
2013 }
2014 }
2015}
static std::string nname(const itype_id &id, unsigned int quantity=1)
Returns the translated item name for the item with given id.
Definition: item.cpp:9922
std::vector< iteminfo > info() const
Return all the information about the item and its type as a vector.
Definition: item.cpp:3971
ammotype ammo_type() const
Ammo type of an ammo item.
Definition: item.cpp:7593
bool test(const iteminfo_parts &value) const
static const ammo_effect_str_id ammo_effect_NEVER_MISFIRES("NEVER_MISFIRES")
static float get_ranged_armor_mult(const common_ranged_data &ranged)
Definition: item.cpp:1100
static const ammo_effect_str_id ammo_effect_INCENDIARY("INCENDIARY")
static const ammo_effect_str_id ammo_effect_BLACKPOWDER("BLACKPOWDER")
static void insert_separation_line(std::vector< iteminfo > &info)
Definition: item.cpp:1301
static int get_ranged_pierce(const common_ranged_data &ranged)
Definition: item.cpp:1091
static const ammo_effect_str_id ammo_effect_RECYCLED("RECYCLED")
@ AMMO_DAMAGE_AP_PROPORTIONAL
std::string name(type dir)
Get Human readable name of a direction.
Definition: overmap.cpp:4127
int dispersion
Dispersion "bonus" from gun.
Definition: itype.h:420
damage_instance damage
Damage, armor piercing and multipliers for each.
Definition: itype.h:412
int range
Range bonus from gun.
Definition: itype.h:416
std::vector< damage_unit > damage_units
Definition: damage.h:52
float total_damage() const
Definition: damage.cpp:75
bool empty() const
Definition: damage.cpp:88
std::optional< bool > force_stat_display
Some combat ammo might not have a damage value Set this to make it show as combat ammo anyway.
Definition: itype.h:733
std::optional< shape_factory > shape
AoE shape or null if it's a projectile.
Definition: itype.h:738
int recoil
Recoil (per shot), roughly equivalent to kinetic energy (in Joules)
Definition: itype.h:713
std::set< ammo_effect_str_id > ammo_effects
See ammo_effect struct.
Definition: itype.h:705
@ no_newline
Do not follow with a newline.
Definition: item.h:147
@ is_decimal
Print as decimal rather than integer.
Definition: item.h:145
@ lower_is_better
Lower values are better for this stat.
Definition: item.h:148
cata::value_ptr< islot_ammo > ammo
Definition: itype.h:864
#define _(msg)
Definition: translations.h:116

References _, itype::ammo, AMMO_DAMAGE_AP, AMMO_DAMAGE_AP_PROPORTIONAL, AMMO_DAMAGE_DISPERSION, AMMO_DAMAGE_PROPORTIONAL, AMMO_DAMAGE_RANGE, AMMO_DAMAGE_RECOIL, AMMO_DAMAGE_VALUE, ammo_data(), ammo_effect_BLACKPOWDER, ammo_effect_INCENDIARY, ammo_effect_NEVER_MISFIRES, ammo_effect_RECYCLED, islot_ammo::ammo_effects, AMMO_FX_BLACKPOWDER, AMMO_FX_CANTMISSFIRE, AMMO_FX_INCENDIARY, AMMO_FX_RECYCLED, ammo_remaining(), AMMO_REMAINING_OR_TYPES, AMMO_SHAPE, ammo_type(), common_ranged_data::damage, damage_instance::damage_units, common_ranged_data::dispersion, damage_instance::empty(), islot_ammo::force_stat_display, get_ranged_armor_mult(), get_ranged_pierce(), info(), insert_separation_line(), is_ammo(), iteminfo::is_decimal, is_gun(), iteminfo::lower_is_better, om_direction::name(), nname(), iteminfo::no_newline, common_ranged_data::range, islot_ammo::recoil, islot_ammo::shape, sign::space, string_format(), iteminfo_query::test(), and damage_instance::total_damage().

Referenced by info().

◆ ammo_remaining()

int item::ammo_remaining ( ) const

Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.

Definition at line 7387 of file item.cpp.

7388{
7389 const item *mag = magazine_current();
7390 if( mag ) {
7391 return mag->ammo_remaining();
7392 }
7393
7394 if( is_tool() || is_gun() ) {
7395 // includes auxiliary gunmods
7397 int power = units::to_kilojoule( get_avatar().get_power_level() );
7398 return power;
7399 }
7400 return charges;
7401 }
7402
7403 if( is_magazine() || is_bandolier() ) {
7404 int res = 0;
7405 for( const item *e : contents.all_items_top() ) {
7406 res += e->charges;
7407 }
7408 return res;
7409 }
7410
7411 return 0;
7412}

References item_contents::all_items_top(), ammo_remaining(), charges, contents, flag_USES_BIONIC_POWER(), get_avatar(), has_flag(), is_bandolier(), is_gun(), is_magazine(), is_tool(), magazine_current(), and units::to_kilojoule().

Referenced by game::add_artifact_dreams(), ammo_consume(), character_funcs::ammo_count_for(), ammo_info(), ammo_remaining(), vehicle_part::ammo_remaining(), turret_data::ammo_remaining(), vehicle_part::ammo_set(), ammo_sufficient(), item_funcs::can_be_unloaded(), turret_data::can_reload(), turret_data::can_unload(), firestarter_actor::can_use(), Character::consume_charges(), iuse::cs_lajatang_off(), Character::deactivate_bionic(), display_name(), npc::do_reload(), aim_activity_actor::do_turn(), iuse::ehandcuffs(), iuse::einktabletpc(), fill_with(), ranged::fire_gun(), character_funcs::fmt_wielded_weapon(), iuse::foodperson(), get_remaining_capacity_for_liquid(), getlight_emit(), gun_recoil(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), activity_handlers::hand_crank_do_turn(), Character::has_enough_charges(), ideal_ranged_dps(), vehicle::interact_with(), is_gunmod_compatible(), is_reloadable_helper(), item(), item_action_generator::map_actions_to_items(), Item_modifier::modify(), iuse::multicooker(), iuse::oxytorch(), target_ui::panel_gun_info(), price(), game::process_artifact(), Character::process_items(), relic_funcs::process_recharge(), process_vehicle_items(), item_reload_option::qty(), iuse::radio_on(), avatar_action::reload(), reload(), activity_handlers::repair_item_finish(), item_funcs::shots_remaining(), iuse::tazer2(), tool_info(), units_remaining(), avatar_funcs::unload_item(), charger_tile::update_internal(), iuse::vibe(), activity_handlers::vibe_do_turn(), wants_to_reload(), wants_to_reload_with(), weapon_inventory_preset::weapon_inventory_preset(), and weight().

◆ ammo_required()

int item::ammo_required ( ) const

Quantity of ammunition consumed per usage of tool or with each shot of gun.

Definition at line 7457 of file item.cpp.

7458{
7459 if( is_tool() ) {
7460 return std::max( type->charges_to_use(), 0 );
7461 }
7462
7463 if( is_gun() ) {
7464 if( ammo_types().empty() ) {
7465 return 0;
7466 } else if( has_flag( flag_FIRE_100 ) ) {
7467 return 100;
7468 } else if( has_flag( flag_FIRE_50 ) ) {
7469 return 50;
7470 } else if( has_flag( flag_FIRE_20 ) ) {
7471 return 20;
7472 } else {
7473 return 1;
7474 }
7475 }
7476
7477 return 0;
7478}
static const std::string flag_FIRE_100("FIRE_100")
static const std::string flag_FIRE_50("FIRE_50")
static const std::string flag_FIRE_20("FIRE_20")
int charges_to_use() const
Definition: itype.cpp:110

References ammo_types(), itype::charges_to_use(), flag_FIRE_100(), flag_FIRE_20(), flag_FIRE_50(), has_flag(), is_gun(), is_tool(), and type.

Referenced by character_funcs::ammo_count_for(), turret_data::ammo_options(), ammo_sufficient(), firestarter_actor::can_use(), cauterize_actor::can_use(), Character::consume_charges(), salvage_actor::cut_up(), display_name(), npc::do_reload(), ranged::fire_gun(), mattack::frag(), activity_handlers::game_do_turn(), activatable_inventory_preset::get_denial(), gun_recoil(), ranged::gunmode_checks_weapon(), Character::has_enough_charges(), vehicle::interact_with(), activity_handlers::jackhammer_finish(), item_action_generator::map_actions_to_items(), iuse::oxytorch(), activity_handlers::oxytorch_do_turn(), activity_handlers::pickaxe_finish(), iuse::portable_game(), turret_data::prepare_fire(), npc::pretend_fire(), process_tool(), turret_data::query(), activity_handlers::repair_item_finish(), mattack::rifle(), item_funcs::shots_remaining(), mattack::tankgun(), units_sufficient(), inscribe_actor::use(), cauterize_actor::use(), enzlave_actor::use(), wants_to_reload(), and wants_to_reload_with().

◆ ammo_set()

item & item::ammo_set ( const itype_id ammo,
int  qty = -1 
)

Filter setting the ammo for this instance Any existing ammo is removed.

If necessary a magazine is also added.

Parameters
ammospecific type of ammo (must be compatible with item ammo type)
qtymaximum ammo (capped by item capacity) or negative to fill to capacity
Returns
same instance to allow method chaining

Definition at line 590 of file item.cpp.

591{
592 if( qty < 0 ) {
593 // completely fill an integral or existing magazine
595 qty = ammo_capacity();
596
597 // else try to add a magazine using default ammo count property if set
598 } else if( !magazine_default().is_null() ) {
599 item mag( magazine_default() );
600 if( mag.type->magazine->count > 0 ) {
601 qty = mag.type->magazine->count;
602 } else {
603 qty = item( magazine_default() ).ammo_capacity();
604 }
605 }
606 }
607
608 if( qty <= 0 ) {
609 ammo_unset();
610 return *this;
611 }
612
613 // handle reloadable tools and guns with no specific ammo type as special case
614 if( ( ammo.is_null() && ammo_types().empty() ) || is_money() ) {
615 if( ( is_tool() || is_gun() ) && magazine_integral() ) {
616 curammo = nullptr;
617 charges = std::min( qty, ammo_capacity() );
618 }
619 return *this;
620 }
621
622 // check ammo is valid for the item
623 const itype *atype = &*ammo;
624 if( !atype->ammo || !ammo_types().count( atype->ammo->type ) ) {
625 debugmsg( "Tried to set invalid ammo %s[%d] for %s", atype->get_id(), qty, typeId() );
626 return *this;
627 }
628
629 if( is_magazine() ) {
630 ammo_unset();
631 item set_ammo( ammo, calendar::turn, std::min( qty, ammo_capacity() ) );
632 if( has_flag( flag_NO_UNLOAD ) ) {
633 set_ammo.set_flag( "NO_DROP" );
634 set_ammo.set_flag( "IRREMOVABLE" );
635 }
636 put_in( set_ammo );
637
638 } else if( magazine_integral() ) {
639 curammo = atype;
640 charges = std::min( qty, ammo_capacity() );
641
642 } else {
643 if( !magazine_current() ) {
645 if( !mag->magazine ) {
646 debugmsg( "Tried to set ammo %s[%d] without suitable magazine for %s",
647 atype->get_id(), qty, typeId() );
648 return *this;
649 }
650
651 // if default magazine too small fetch instead closest available match
652 if( mag->magazine->capacity < qty ) {
653 // as above call to magazine_default successful can infer minimum one option exists
654 auto iter = type->magazines.find( atype->ammo->type );
655 if( iter == type->magazines.end() ) {
656 debugmsg( "%s doesn't have a magazine for %s",
657 typeId(), ammo );
658 return *this;
659 }
660 std::vector<itype_id> opts( iter->second.begin(), iter->second.end() );
661 std::sort( opts.begin(), opts.end(), []( const itype_id & lhs, const itype_id & rhs ) {
662 return lhs->magazine->capacity < rhs->magazine->capacity;
663 } );
664 mag = opts.back();
665 for( const itype_id &e : opts ) {
666 if( e->magazine->capacity >= qty ) {
667 mag = e;
668 break;
669 }
670 }
671 }
672 put_in( item( mag ) );
673 }
674 magazine_current()->ammo_set( ammo, qty );
675 }
676
677 return *this;
678}
bool is_money() const
Definition: item.cpp:6000
item & ammo_unset()
Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-o...
Definition: item.cpp:680
bool is_null() const
Returns whether this represents the id of the null-object (in which case it's the null-id).
Definition: string_id.h:317
static const std::string flag_NO_UNLOAD("NO_UNLOAD")
std::map< ammotype, std::set< itype_id > > magazines
Magazine types (if any) for each ammo type that can be used to reload this item.
Definition: itype.h:1020

References itype::ammo, ammo_capacity(), ammo_set(), ammo_types(), ammo_unset(), charges, count(), curammo, debugmsg, flag_NO_UNLOAD(), itype::get_id(), has_flag(), is_gun(), is_magazine(), is_money(), is_null(), string_id< T >::is_null(), is_tool(), item(), itype::magazine, magazine_current(), magazine_default(), magazine_integral(), itype::magazines, put_in(), set_flag(), calendar::turn, type, and typeId().

Referenced by Character::activate_bionic(), ammo_set(), vehicle_part::ammo_set(), mdeath::broken(), npc::check_toggle_cbm(), crafting::complete_disassemble(), vehicle_part::deserialize(), game::dump_stats(), fill_with(), find_reloadable_cbms(), basecamp::form_crafting_inventory(), mattack::frag(), gun_info(), npc_ai::gun_value(), activity_handlers::hand_crank_do_turn(), vehicle::interact_with(), item(), Item_modifier::modify(), relic_funcs::process_recharge_entry(), mattack::rifle(), gun_actor::shoot(), npc::starting_weapon(), mattack::tankgun(), avatar_funcs::unload_item(), iuse_transform::use(), npc_ai::wielded_value(), and debug_menu::wishitem().

◆ ammo_sort_name()

std::string item::ammo_sort_name ( ) const

Definition at line 7651 of file item.cpp.

7652{
7653 if( is_magazine() || is_gun() || is_tool() ) {
7654 const std::set<ammotype> &types = ammo_types();
7655 if( !types.empty() ) {
7656 return ammotype( *types.begin() )->name();
7657 }
7658 }
7659 if( is_ammo() ) {
7660 return ammo_type()->name();
7661 }
7662 return "";
7663}
std::string name() const
Definition: ammo.cpp:79

References ammo_type(), ammo_types(), is_ammo(), is_gun(), is_magazine(), is_tool(), and ammunition_type::name().

◆ ammo_sufficient()

bool item::ammo_sufficient ( int  qty = 1) const

Check if sufficient ammo is loaded for given number of uses.

Check if there is enough ammo loaded in a tool for the given number of uses or given number of gun shots. Using this function for this check is preferred because we expect to add support for items consuming multiple ammo types in the future. Users of this function will not need to be refactored when this happens.

Parameters
[in]qtyNumber of uses
Returns
true if ammo sufficient for number of uses is loaded, false otherwise

Definition at line 7480 of file item.cpp.

7481{
7482 return ammo_remaining() >= ammo_required() * qty;
7483}
int ammo_required() const
Quantity of ammunition consumed per usage of tool or with each shot of gun.
Definition: item.cpp:7457

References ammo_remaining(), and ammo_required().

Referenced by can_do_activity_there(), iuse::extinguisher(), ranged::gunmode_checks_weapon(), Character::has_enough_charges(), iuse::jet_injector(), item_action_generator::map_actions_to_items(), mine_activity(), avatar_action::move(), iuse::pheromone(), iuse::portal(), turret_data::query(), iuse::radiocar(), iuse::radiocaron(), examine_item_menu::rate_action_use(), iuse::rm13armor_off(), iuse::shavekit(), gun_actor::shoot(), iuse::stimpack(), and iuse::teleport().

◆ ammo_type()

ammotype item::ammo_type ( ) const

Ammo type of an ammo item.

Returns
ammotype of ammo item or a null id if the item is not ammo

Definition at line 7593 of file item.cpp.

7594{
7595 if( is_ammo() ) {
7596 return type->ammo->type;
7597 }
7598 return ammotype::NULL_ID();
7599}

References itype::ammo, is_ammo(), string_id< ammunition_type >::NULL_ID(), and type.

Referenced by vehicle::add_item(), ammo_info(), ammo_sort_name(), mdeath::broken(), color_in_inventory(), detonate(), character_funcs::find_ammo_helper(), character_funcs::get_ammo_items(), item_reload_option::qty(), reload(), and npc::value().

◆ ammo_types()

const std::set< ammotype > & item::ammo_types ( bool  conversion = true) const

Set of ammo types (ammunition_type) used by item.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
empty set if item does not use a specific ammo type (and is consequently not reloadable)

Definition at line 7570 of file item.cpp.

7571{
7572 if( conversion ) {
7573 const std::vector<const item *> &mods = is_gun() ? gunmods() : toolmods();
7574 for( const item *e : mods ) {
7575 if( !e->type->mod->ammo_modifier.empty() ) {
7576 return e->type->mod->ammo_modifier;
7577 }
7578 }
7579 }
7580
7581 if( is_gun() ) {
7582 return type->gun->ammo;
7583 } else if( is_tool() ) {
7584 return type->tool->ammo_id;
7585 } else if( is_magazine() ) {
7586 return type->magazine->type;
7587 }
7588
7589 static std::set<ammotype> atypes = {};
7590 return atypes;
7591}

References itype::gun, gunmods(), is_gun(), is_magazine(), is_tool(), itype::magazine, itype::tool, toolmods(), and type.

Referenced by vehicle::add_item(), allow_crafting_component(), ammo_default(), turret_data::ammo_options(), ammo_required(), ammo_set(), ammo_sort_name(), mdeath::broken(), item_funcs::can_be_unloaded(), color_in_inventory(), common_ammo_default(), craft_has_charges(), display_name(), avatar_action::fire_wielded_weapon(), get_quality(), avatar_funcs::gunmod_add(), vehicle_part::is_battery(), is_gunmod_compatible(), is_money(), is_reloadable(), is_reloadable_helper(), item(), magazine_compatible(), magazine_default(), magazine_info(), Item_modifier::modify(), price(), relic_funcs::process_recharge_entry(), character_funcs::select_ammo(), set_countdown(), tool_info(), avatar_funcs::unload_item(), npc::value(), and weight().

◆ ammo_unset()

item & item::ammo_unset ( )

Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-op For items reloading using magazines any empty magazine remains present.

Definition at line 680 of file item.cpp.

681{
682 if( !is_tool() && !is_gun() && !is_magazine() ) {
683 // do nothing
684 } else if( is_magazine() ) {
686 } else if( magazine_integral() ) {
687 curammo = nullptr;
688 charges = 0;
689 } else if( magazine_current() ) {
691 }
692
693 return *this;
694}

References ammo_unset(), charges, item_contents::clear_items(), contents, curammo, is_gun(), is_magazine(), is_tool(), magazine_current(), and magazine_integral().

Referenced by ammo_set(), ammo_unset(), vehicle_part::ammo_unset(), iuse::ehandcuffs(), emit_radio_signal(), npc_ai::gun_value(), and ammobelt_actor::use().

◆ animal_armor_info()

void item::animal_armor_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2715 of file item.cpp.

2717{
2718 if( !is_pet_armor() ) {
2719 return;
2720 }
2721
2722 const std::string space = " ";
2723
2724 int converted_storage_scale = 0;
2725 const double converted_storage = round_up( convert_volume( get_storage().value(),
2726 &converted_storage_scale ), 2 );
2727 if( parts->test( iteminfo_parts::ARMOR_STORAGE ) && converted_storage > 0 ) {
2728 const iteminfo::flags f = converted_storage_scale == 0 ? iteminfo::no_flags : iteminfo::is_decimal;
2729 info.push_back( iteminfo( "ARMOR", space + _( "Storage: " ),
2730 string_format( "<num> %s", volume_units_abbr() ),
2731 f, converted_storage ) );
2732 }
2733
2734 // Whatever the last entry was, we want a newline at this point
2735 info.back().bNewLine = true;
2736
2737 armor_protection_info( info, parts, batch, debug );
2738}
double round_up(double val, unsigned int dp)
Round a value up at a given decimal place.
units::volume get_storage() const
Returns the storage amount (islot_armor::storage) that this item provides when worn.
Definition: item.cpp:5732
void armor_protection_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2489
bool is_pet_armor(bool on_pet=false) const
Definition: item.cpp:6698
constexpr auto debug
Definition: options.cpp:151
Value and metadata for one property of an item.
Definition: item.h:108
flags
Definition: item.h:143
@ no_flags
Definition: item.h:144
const char * volume_units_abbr()
Create an abbreviated units label for a volume value.
double convert_volume(int volume)
Convert volume from ml to units defined by user.

References _, armor_protection_info(), ARMOR_STORAGE, convert_volume(), debug, get_storage(), info(), iteminfo::is_decimal, is_pet_armor(), iteminfo::no_flags, round_up(), sign::space, string_format(), iteminfo_query::test(), and volume_units_abbr().

Referenced by info().

◆ armor_fit_info()

void item::armor_fit_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2740 of file item.cpp.

2742{
2743 if( !is_armor() ) {
2744 return;
2745 }
2746
2747 avatar &you = get_avatar();
2748 int encumbrance = get_encumber( you );
2749 const sizing sizing_level = get_sizing( you, encumbrance != 0 );
2750
2753 info.push_back( iteminfo( "DESCRIPTION",
2754 _( "* This item can be <info>worn with a "
2755 "helmet</info>." ) ) );
2756 }
2757
2759 switch( sizing_level ) {
2761 if( has_flag( flag_FIT ) ) {
2762 info.emplace_back( "DESCRIPTION",
2763 _( "* This clothing <info>fits</info> you perfectly." ) );
2764 }
2765 break;
2767 if( has_flag( flag_FIT ) ) {
2768 info.emplace_back( "DESCRIPTION", _( "* This clothing <info>fits</info> "
2769 "your large frame perfectly." ) );
2770 }
2771 break;
2773 if( has_flag( flag_FIT ) ) {
2774 info.emplace_back( "DESCRIPTION", _( "* This clothing <info>fits</info> "
2775 "your small frame perfectly." ) );
2776 }
2777 break;
2779 info.emplace_back( "DESCRIPTION", _( "* This clothing is <bad>oversized</bad> "
2780 "and does <bad>not fit</bad> you." ) );
2781 break;
2783 info.emplace_back( "DESCRIPTION",
2784 _( "* This clothing is hilariously <bad>oversized</bad> "
2785 "and does <bad>not fit</bad> your <info>abnormally "
2786 "small mutated anatomy</info>." ) );
2787 break;
2789 info.emplace_back( "DESCRIPTION",
2790 _( "* This clothing is <bad>normal sized</bad> and does "
2791 "<bad>not fit</info> your <info>abnormally large "
2792 "mutated anatomy</info>." ) );
2793 break;
2795 info.emplace_back( "DESCRIPTION",
2796 _( "* This clothing is <bad>normal sized</bad> and does "
2797 "<bad>not fit</bad> your <info>abnormally small "
2798 "mutated anatomy</info>." ) );
2799 break;
2801 info.emplace_back( "DESCRIPTION",
2802 _( "* This clothing is hilariously <bad>undersized</bad> "
2803 "and does <bad>not fit</bad> your <info>abnormally "
2804 "large mutated anatomy</info>." ) );
2805 break;
2807 info.emplace_back( "DESCRIPTION", _( "* This clothing is <bad>undersized</bad> "
2808 "and does <bad>not fit</bad> you." ) );
2809 break;
2810 default:
2811 break;
2812 }
2813 }
2814
2816 if( has_flag( flag_VARSIZE ) ) {
2817 std::string resize_str;
2818 if( has_flag( flag_FIT ) ) {
2819 switch( sizing_level ) {
2821 resize_str = _( "<info>can be upsized</info>" );
2822 break;
2824 resize_str = _( "<info>can be downsized</info>" );
2825 break;
2828 resize_str = _( "<bad>can not be downsized</bad>" );
2829 break;
2832 resize_str = _( "<bad>can not be upsized</bad>" );
2833 break;
2834 default:
2835 break;
2836 }
2837 if( !resize_str.empty() ) {
2838 std::string info_str = string_format( _( "* This clothing %s." ), resize_str );
2839 info.push_back( iteminfo( "DESCRIPTION", info_str ) );
2840 }
2841 } else {
2842 switch( sizing_level ) {
2844 resize_str = _( " and <info>upsized</info>" );
2845 break;
2847 resize_str = _( " and <info>downsized</info>" );
2848 break;
2851 resize_str = _( " but <bad>not downsized</bad>" );
2852 break;
2855 resize_str = _( " but <bad>not upsized</bad>" );
2856 break;
2857 default:
2858 break;
2859 }
2860 std::string info_str = string_format( _( "* This clothing <info>can be "
2861 "refitted</info>%s." ), resize_str );
2862 info.push_back( iteminfo( "DESCRIPTION", info_str ) );
2863 }
2864 } else {
2865 info.emplace_back( "DESCRIPTION", _( "* This clothing <bad>can not be refitted, "
2866 "upsized, or downsized</bad>." ) );
2867 }
2868 }
2869
2871 info.push_back( iteminfo( "DESCRIPTION",
2872 _( "* This item can be worn on <info>either side</info> of "
2873 "the body." ) ) );
2874 }
2875 if( ( is_power_armor() ) &&
2879 info.push_back( iteminfo( "DESCRIPTION",
2880 _( "* When worn with a power armor suit, it will "
2881 "<good>fully protect</good> you from "
2882 "<info>radiation</info>." ) ) );
2883 } else if( has_flag( flag_POWERARMOR_EXO ) ) {
2884 info.push_back( iteminfo( "DESCRIPTION",
2885 _( "* When worn with a power armor helmet, it will "
2886 "<good>fully protect</good> you from " "<info>radiation</info>." ) ) );
2887 }
2888 }
2889 }
2891 info.push_back( iteminfo( "DESCRIPTION",
2892 string_format( _( "* The film strip on the badge is %s." ),
2894 }
2895}
@ bp_head
Definition: bodypart.h:41
bool is_sided() const
Returns true if item is armor and can be worn on different sides of the body.
Definition: item.cpp:802
int irradiation
Definition: item.h:2211
bool is_power_armor() const
Whether this is a power armor item.
Definition: item.cpp:5786
sizing
Definition: item.h:2130
@ small_sized_small_char
@ human_sized_human_char
@ small_sized_human_char
@ human_sized_small_char
bool is_armor() const
Definition: item.cpp:6704
sizing get_sizing(const Character &, bool) const
Definition: item.cpp:1177
int get_encumber(const Character &) const
Returns the encumbrance value that this item has when worn by given player.
Definition: item.cpp:5792
bool covers(body_part bp) const
Whether this item (when worn) covers the given body part.
Definition: item.cpp:743
static const std::string flag_FIT("FIT")
static const std::string flag_HELMET_COMPAT("HELMET_COMPAT")
static const std::string flag_POWERARMOR_EXO("POWERARMOR_EXO")
static const itype_id itype_rad_badge("rad_badge")
static const std::string flag_VARSIZE("VARSIZE")
static const std::string flag_POWERARMOR_EXTERNAL("POWERARMOR_EXTERNAL")
std::string rad_badge_color(const int rad)
Definition: item.cpp:289
@ DESCRIPTION_FLAGS_POWERARMOR
@ DESCRIPTION_FLAGS_POWERARMOR_RADIATIONHINT
@ DESCRIPTION_FLAGS_HELMETCOMPAT

References _, big_sized_big_char, big_sized_human_char, big_sized_small_char, bp_head, covers(), DESCRIPTION_FLAGS_FITS, DESCRIPTION_FLAGS_HELMETCOMPAT, DESCRIPTION_FLAGS_POWERARMOR, DESCRIPTION_FLAGS_POWERARMOR_RADIATIONHINT, DESCRIPTION_FLAGS_SIDED, DESCRIPTION_FLAGS_VARSIZE, DESCRIPTION_IRRADIATION, flag_FIT(), flag_HELMET_COMPAT(), flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_VARSIZE(), get_avatar(), get_encumber(), get_sizing(), has_flag(), human_sized_big_char, human_sized_human_char, human_sized_small_char, info(), irradiation, is_armor(), is_power_armor(), is_sided(), itype_rad_badge, rad_badge_color(), small_sized_big_char, small_sized_human_char, small_sized_small_char, string_format(), iteminfo_query::test(), and typeId().

Referenced by final_info().

◆ armor_info()

void item::armor_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2532 of file item.cpp.

2534{
2535 if( !is_armor() ) {
2536 return;
2537 }
2538
2539 avatar &you = get_avatar();
2540 int encumbrance = get_encumber( you );
2541 const sizing sizing_level = get_sizing( you, encumbrance != 0 );
2542 const std::string space = " ";
2543 body_part_set covered_parts = get_covered_body_parts();
2544 bool covers_anything = covered_parts.any();
2545
2546 if( parts->test( iteminfo_parts::ARMOR_BODYPARTS ) ) {
2548 std::string coverage = _( "<bold>Covers</bold>: " );
2549 if( covers( bp_head ) ) {
2550 coverage += _( "The <info>head</info>. " );
2551 }
2552 if( covers( bp_eyes ) ) {
2553 coverage += _( "The <info>eyes</info>. " );
2554 }
2555 if( covers( bp_mouth ) ) {
2556 coverage += _( "The <info>mouth</info>. " );
2557 }
2558 if( covers( bp_torso ) ) {
2559 coverage += _( "The <info>torso</info>. " );
2560 }
2561
2562 if( is_sided() && ( covers( bp_arm_l ) || covers( bp_arm_r ) ) ) {
2563 coverage += _( "Either <info>arm</info>. " );
2564 } else if( covers( bp_arm_l ) && covers( bp_arm_r ) ) {
2565 coverage += _( "The <info>arms</info>. " );
2566 } else if( covers( bp_arm_l ) ) {
2567 coverage += _( "The <info>left arm</info>. " );
2568 } else if( covers( bp_arm_r ) ) {
2569 coverage += _( "The <info>right arm</info>. " );
2570 }
2571
2572 if( is_sided() && ( covers( bp_hand_l ) || covers( bp_hand_r ) ) ) {
2573 coverage += _( "Either <info>hand</info>. " );
2574 } else if( covers( bp_hand_l ) && covers( bp_hand_r ) ) {
2575 coverage += _( "The <info>hands</info>. " );
2576 } else if( covers( bp_hand_l ) ) {
2577 coverage += _( "The <info>left hand</info>. " );
2578 } else if( covers( bp_hand_r ) ) {
2579 coverage += _( "The <info>right hand</info>. " );
2580 }
2581
2582 if( is_sided() && ( covers( bp_leg_l ) || covers( bp_leg_r ) ) ) {
2583 coverage += _( "Either <info>leg</info>. " );
2584 } else if( covers( bp_leg_l ) && covers( bp_leg_r ) ) {
2585 coverage += _( "The <info>legs</info>. " );
2586 } else if( covers( bp_leg_l ) ) {
2587 coverage += _( "The <info>left leg</info>. " );
2588 } else if( covers( bp_leg_r ) ) {
2589 coverage += _( "The <info>right leg</info>. " );
2590 }
2591
2592 if( is_sided() && ( covers( bp_foot_l ) || covers( bp_foot_r ) ) ) {
2593 coverage += _( "Either <info>foot</info>. " );
2594 } else if( covers( bp_foot_l ) && covers( bp_foot_r ) ) {
2595 coverage += _( "The <info>feet</info>. " );
2596 } else if( covers( bp_foot_l ) ) {
2597 coverage += _( "The <info>left foot</info>. " );
2598 } else if( covers( bp_foot_r ) ) {
2599 coverage += _( "The <info>right foot</info>. " );
2600 }
2601
2602 if( !covers_anything ) {
2603 coverage += _( "<info>Nothing</info>." );
2604 }
2605
2606 info.push_back( iteminfo( "ARMOR", coverage ) );
2607 }
2608
2609 if( parts->test( iteminfo_parts::ARMOR_LAYER ) && covers_anything ) {
2610 std::string layering = _( "Layer: " );
2611 if( has_flag( flag_PERSONAL ) ) {
2612 layering += _( "<stat>Personal aura</stat>. " );
2613 } else if( has_flag( flag_SKINTIGHT ) ) {
2614 layering += _( "<stat>Close to skin</stat>. " );
2615 } else if( has_flag( flag_BELTED ) ) {
2616 layering += _( "<stat>Strapped</stat>. " );
2617 } else if( has_flag( flag_OUTER ) ) {
2618 layering += _( "<stat>Outer</stat>. " );
2619 } else if( has_flag( flag_WAIST ) ) {
2620 layering += _( "<stat>Waist</stat>. " );
2621 } else if( has_flag( flag_AURA ) ) {
2622 layering += _( "<stat>Outer aura</stat>. " );
2623 } else {
2624 layering += _( "<stat>Normal</stat>. " );
2625 }
2626
2627 info.push_back( iteminfo( "ARMOR", layering ) );
2628 }
2629
2630 if( parts->test( iteminfo_parts::ARMOR_COVERAGE ) && covers_anything ) {
2631 info.push_back( iteminfo( "ARMOR", _( "Coverage: " ), "<num>%",
2633 }
2634 if( parts->test( iteminfo_parts::ARMOR_WARMTH ) && covers_anything ) {
2635 info.push_back( iteminfo( "ARMOR", space + _( "Warmth: " ), get_warmth() ) );
2636 }
2637
2639
2640 if( parts->test( iteminfo_parts::ARMOR_ENCUMBRANCE ) && covers_anything ) {
2641 std::string format;
2642 if( has_flag( flag_FIT ) ) {
2643 format = _( "<num> <info>(fits)</info>" );
2644 } else if( has_flag( flag_VARSIZE ) && encumbrance ) {
2645 format = _( "<num> <bad>(poor fit)</bad>" );
2646 }
2647
2648 //If we have the wrong size, we do not fit so alert the player
2649 if( sizing_level == sizing::human_sized_small_char ) {
2650 format = _( "<num> <bad>(too big)</bad>" );
2651 } else if( sizing_level == sizing::big_sized_small_char ) {
2652 format = _( "<num> <bad>(huge!)</bad>" );
2653 } else if( sizing_level == sizing::small_sized_human_char ||
2654 sizing_level == sizing::human_sized_big_char ) {
2655 format = _( "<num> <bad>(too small)</bad>" );
2656 } else if( sizing_level == sizing::small_sized_big_char ) {
2657 format = _( "<num> <bad>(tiny!)</bad>" );
2658 }
2659
2660 info.push_back( iteminfo( "ARMOR", _( "<bold>Encumbrance</bold>: " ), format,
2662 encumbrance ) );
2663 if( !type->rigid ) {
2664 const int encumbrance_when_full =
2666 info.push_back( iteminfo( "ARMOR", space + _( "Encumbrance when full: " ), "",
2668 encumbrance_when_full ) );
2669 }
2670 }
2671
2672 int converted_storage_scale = 0;
2673 const double converted_storage = round_up( convert_volume( get_storage().value(),
2674 &converted_storage_scale ), 2 );
2675 if( parts->test( iteminfo_parts::ARMOR_STORAGE ) && converted_storage > 0 ) {
2676 const iteminfo::flags f = converted_storage_scale == 0 ? iteminfo::no_flags : iteminfo::is_decimal;
2677 info.push_back( iteminfo( "ARMOR", space + _( "Storage: " ),
2678 string_format( "<num> %s", volume_units_abbr() ),
2679 f, converted_storage ) );
2680 }
2681
2682 // Whatever the last entry was, we want a newline at this point
2683 info.back().bNewLine = true;
2684
2685 if( covers_anything ) {
2686 armor_protection_info( info, parts, batch, debug );
2687 }
2688
2689 const units::mass weight_bonus = get_weight_capacity_bonus();
2690 const float weight_modif = get_weight_capacity_modifier();
2691 if( weight_modif != 1 ) {
2692 std::string modifier;
2693 if( weight_modif < 1 ) {
2694 modifier = "<num><bad>x</bad>";
2695 } else {
2696 modifier = "<num><color_light_green>x</color>";
2697 }
2698 info.push_back( iteminfo( "ARMOR",
2699 _( "<bold>Weight capacity modifier</bold>: " ), modifier,
2700 iteminfo::no_newline | iteminfo::is_decimal, weight_modif ) );
2701 }
2702 if( weight_bonus != 0_gram ) {
2703 std::string bonus;
2704 if( weight_bonus < 0_gram ) {
2705 bonus = string_format( "<num> <bad>%s</bad>", weight_units() );
2706 } else {
2707 bonus = string_format( "<num> <color_light_green> %s</color>", weight_units() );
2708 }
2709 info.push_back( iteminfo( "ARMOR", _( "<bold>Weight capacity bonus</bold>: " ), bonus,
2711 convert_weight( weight_bonus ) ) );
2712 }
2713}
@ bp_foot_l
Definition: bodypart.h:50
@ bp_leg_r
Definition: bodypart.h:49
@ bp_eyes
Definition: bodypart.h:42
@ bp_hand_l
Definition: bodypart.h:46
@ bp_arm_l
Definition: bodypart.h:44
@ bp_leg_l
Definition: bodypart.h:48
@ bp_hand_r
Definition: bodypart.h:47
@ bp_torso
Definition: bodypart.h:40
@ bp_mouth
Definition: bodypart.h:43
@ bp_foot_r
Definition: bodypart.h:51
@ bp_arm_r
Definition: bodypart.h:45
bool any() const
Definition: bodypart.h:248
units::volume get_total_capacity() const
It returns the maximum volume of any contents, including liquids, ammo, magazines,...
Definition: item.cpp:8409
int get_encumber_when_containing(const Character &, const units::volume &contents_volume) const
Returns the encumbrance value that this item has when worn by given player, when containing a particu...
Definition: item.cpp:5820
units::mass get_weight_capacity_bonus() const
Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides whe...
Definition: item.cpp:5754
body_part_set get_covered_body_parts() const
Bitset of all covered body parts.
Definition: item.cpp:753
int get_warmth() const
Returns the warmth value that this item has when worn.
Definition: item.cpp:5918
int get_coverage() const
Returns the relative coverage that this item has when worn.
Definition: item.cpp:5900
float get_weight_capacity_modifier() const
Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides ...
Definition: item.cpp:5745
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&... args)
\rst Formats arguments and returns the result as a string.
Definition: fmtlib_core.h:2316
static const std::string flag_WAIST("WAIST")
static const std::string flag_BELTED("BELTED")
static const std::string flag_SKINTIGHT("SKINTIGHT")
static const std::string flag_OUTER("OUTER")
static const std::string flag_AURA("AURA")
static const std::string flag_PERSONAL("PERSONAL")
bool rigid
Definition: itype.h:991
const char * weight_units()
Create a units label for a weight value.
double convert_weight(const units::mass &weight)
Convert weight in grams to units defined by user (kg or lbs)

References _, body_part_set::any(), ARMOR_BODYPARTS, ARMOR_COVERAGE, ARMOR_ENCUMBRANCE, ARMOR_LAYER, armor_protection_info(), ARMOR_STORAGE, ARMOR_WARMTH, big_sized_small_char, bp_arm_l, bp_arm_r, bp_eyes, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_head, bp_leg_l, bp_leg_r, bp_mouth, bp_torso, convert_volume(), convert_weight(), covers(), debug, flag_AURA(), flag_BELTED(), flag_FIT(), flag_OUTER(), flag_PERSONAL(), flag_SKINTIGHT(), flag_VARSIZE(), flag_WAIST(), format(), get_avatar(), get_coverage(), get_covered_body_parts(), get_encumber(), get_encumber_when_containing(), get_sizing(), get_storage(), get_total_capacity(), get_warmth(), get_weight_capacity_bonus(), get_weight_capacity_modifier(), has_flag(), human_sized_big_char, human_sized_small_char, info(), insert_separation_line(), is_armor(), iteminfo::is_decimal, is_sided(), iteminfo::lower_is_better, iteminfo::no_flags, iteminfo::no_newline, itype::rigid, round_up(), small_sized_big_char, small_sized_human_char, sign::space, string_format(), iteminfo_query::test(), type, volume_units_abbr(), and weight_units().

Referenced by info().

◆ armor_protection_info()

void item::armor_protection_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2489 of file item.cpp.

2492{
2493 if( !is_armor() && !is_pet_armor() ) {
2494 return;
2495 }
2496
2497 const std::string space = " ";
2498
2499 if( parts->test( iteminfo_parts::ARMOR_PROTECTION ) ) {
2500 info.push_back( iteminfo( "ARMOR", _( "<bold>Protection</bold>: Bash: " ), "",
2502 info.push_back( iteminfo( "ARMOR", space + _( "Cut: " ), "", iteminfo::no_newline, cut_resist() ) );
2503 info.push_back( iteminfo( "ARMOR", space + _( "Ballistic: " ), bullet_resist() ) );
2504 info.push_back( iteminfo( "ARMOR", space + _( "Acid: " ), "",
2506 info.push_back( iteminfo( "ARMOR", space + _( "Fire: " ), "",
2508 info.push_back( iteminfo( "ARMOR", space + _( "Environmental: " ),
2509 get_base_env_resist( *this ) ) );
2510 if( type->can_use( "GASMASK" ) || type->can_use( "DIVE_TANK" ) ) {
2511 info.push_back( iteminfo( "ARMOR",
2512 _( "<bold>Protection when active</bold>: " ) ) );
2513 info.push_back( iteminfo( "ARMOR", space + _( "Acid: " ), "",
2516 info.push_back( iteminfo( "ARMOR", space + _( "Fire: " ), "",
2519 info.push_back( iteminfo( "ARMOR", space + _( "Environmental: " ),
2521 }
2522
2523 if( damage() > 0 ) {
2524 info.push_back( iteminfo( "ARMOR",
2525 _( "Protection values are <bad>reduced by damage</bad> and "
2526 "you may be able to <info>improve them by repairing this "
2527 "item</info>." ) ) );
2528 }
2529 }
2530}
int bash_resist(bool to_self=false) const
Definition: item.cpp:6031
int fire_resist(bool to_self=false, int base_env_resist=0) const
Definition: item.cpp:6161
int acid_resist(bool to_self=false, int base_env_resist=0) const
Resistance against different damage types (damage_type).
Definition: item.cpp:6127
int bullet_resist(bool to_self=false) const
Definition: item.cpp:6098
int get_base_env_resist_w_filter() const
Returns the base resistance to environmental effects if an item (for example a gas mask) requires a g...
Definition: item.cpp:5777
int cut_resist(bool to_self=false) const
Definition: item.cpp:6059
int damage() const
How much damage has the item sustained?
Definition: item.cpp:696
static int get_base_env_resist(const item &it)
Definition: item.cpp:1220
bool can_use(const std::string &iuse_name) const
Definition: itype.cpp:161

References _, acid_resist(), ARMOR_PROTECTION, bash_resist(), bullet_resist(), itype::can_use(), cut_resist(), damage(), fire_resist(), get_base_env_resist(), get_base_env_resist_w_filter(), get_env_resist(), info(), is_armor(), is_pet_armor(), iteminfo::no_newline, sign::space, iteminfo_query::test(), and type.

Referenced by animal_armor_info(), and armor_info().

◆ attack_cost()

int item::attack_cost ( ) const

Base number of moves (Creature::moves) that a single melee attack with this items takes.

The actual time depends heavily on the attacker, see melee.cpp.

Definition at line 5181 of file item.cpp.

5182{
5183 int base = 65 + ( volume() / 62.5_ml + weight() / 60_gram ) / count();
5185 return std::max( 0, base + bonus );
5186}
double bonus_from_enchantments_wielded(double base, enchant_vals::mod value, bool round=false) const
Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantment...
Definition: item.cpp:7006
units::mass weight(bool include_contents=true, bool integral=false) const
Definition: item.cpp:4958
units::volume volume(bool integral=false) const
Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to n...
Definition: item.cpp:5104

References bonus_from_enchantments_wielded(), count(), enchant_vals::ITEM_ATTACK_COST, volume(), and weight().

Referenced by Character::attack_cost(), combat_info(), Character::melee_attack(), npc::move_to(), smash(), and ranged::throw_cost().

◆ average_dps()

double item::average_dps ( const player guy) const

return the average dps of the weapon against evaluation monsters

Definition at line 1448 of file item.cpp.

1449{
1450 double dmg_count = 0.0;
1451 const std::map<std::string, double> &dps_data = dps( false, true, guy );
1452 for( const std::pair<const std::string, double> &dps_entry : dps_data ) {
1453 dmg_count += dps_entry.second;
1454 }
1455 return dmg_count / dps_data.size();
1456}
std::map< std::string, double > dps(bool for_display, bool for_calc, const player &guy) const
calculate effective dps against a stock set of monsters.
Definition: item.cpp:1428

References dps().

Referenced by npc_ai::melee_value().

◆ base_damage_melee()

damage_instance item::base_damage_melee ( ) const

All damage types this item deals when used in melee (no skill modifiers etc.

applied).

Definition at line 5244 of file item.cpp.

5245{
5246 // TODO: Caching
5248 for( size_t i = DT_NULL + 1; i < NUM_DT; i++ ) {
5249 damage_type dt = static_cast<damage_type>( i );
5250 int dam = damage_melee( dt );
5251 if( dam > 0 ) {
5252 ret.add_damage( dt, dam );
5253 }
5254 }
5255
5256 return ret;
5257}
int damage_melee(damage_type dt) const
Damage of given type caused when this item is used as melee weapon.
Definition: item.cpp:5188
damage_type
Definition: damage.h:20
@ DT_NULL
Definition: damage.h:21
@ NUM_DT
Definition: damage.h:32

References damage_melee(), DT_NULL, NUM_DT, and cata::hash64_detail::ret.

◆ base_damage_thrown()

damage_instance item::base_damage_thrown ( ) const

All damage types this item deals when thrown (no skill modifiers etc.

applied).

Definition at line 5259 of file item.cpp.

5260{
5261 // TODO: Create a separate cache for individual items (for modifiers like diamond etc.)
5262 return type->thrown_damage;
5263}
damage_instance thrown_damage
Base damage output when thrown.
Definition: itype.h:996

References itype::thrown_damage, and type.

Referenced by ranged::throw_item().

◆ base_volume()

units::volume item::base_volume ( ) const

Simplified, faster volume check for when processing time is important and exact volume is not.

NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge. If trying to determine how many of an item can fit in a given space, charges_per_volume should be used instead.

Definition at line 5076 of file item.cpp.

5077{
5078 if( is_null() ) {
5079 return 0_ml;
5080 }
5081 if( is_corpse() ) {
5082 return corpse_volume( corpse );
5083 }
5084
5085 if( is_craft() ) {
5086 units::volume ret = 0_ml;
5087 for( const item &it : components ) {
5088 ret += it.base_volume();
5089 }
5090 return ret;
5091 }
5092
5093 if( count_by_charges() ) {
5094 if( type->volume % type->stack_size == 0_ml ) {
5095 return type->volume / type->stack_size;
5096 } else {
5097 return type->volume / type->stack_size + 1_ml;
5098 }
5099 }
5100
5101 return type->volume;
5102}
bool count_by_charges() const
Definition: item.cpp:6005
units::volume corpse_volume(const mtype *corpse) const
Volume check for corpses, helper for base_volume().
Definition: item.cpp:5054
bool is_craft() const
Definition: item.cpp:6923
bool is_corpse() const
Whether this is a corpse item.
Definition: item.cpp:6620
int stack_size
Number of items per above volume for count_by_charges items.
Definition: itype.h:982
units::volume volume
Space occupied by items of this type CAUTION: value given is for a default-sized stack.
Definition: itype.h:974

References components, corpse, corpse_volume(), count_by_charges(), is_corpse(), is_craft(), is_null(), cata::hash64_detail::ret, itype::stack_size, type, and itype::volume.

Referenced by burn(), flammable(), and simulate_burn().

◆ bash_resist()

int item::bash_resist ( bool  to_self = false) const

Definition at line 6031 of file item.cpp.

6032{
6033 if( is_null() ) {
6034 return 0;
6035 }
6036
6037 float resist = 0;
6039 int eff_thickness = 1;
6040
6041 // base resistance
6042 // Don't give reinforced items +armor, just more resistance to ripping
6043 const int dmg = damage_level( 4 );
6044 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6045 eff_thickness = std::max( 1, get_thickness() - eff_damage );
6046
6047 const std::vector<const material_type *> mat_types = made_of_types();
6048 if( !mat_types.empty() ) {
6049 for( const material_type *mat : mat_types ) {
6050 resist += mat->bash_resist();
6051 }
6052 // Average based on number of materials.
6053 resist /= mat_types.size();
6054 }
6055
6056 return std::lround( ( resist * eff_thickness ) + mod );
6057}
int get_thickness() const
Returns the islot_armor::thickness value, or 0 for non-armor.
Definition: item.cpp:5909
int damage_level(int max) const
Scale item damage to the given number of levels.
Definition: item.cpp:701
@ clothing_mod_type_bash
Definition: clothing_mod.h:19
STL namespace.

References clothing_mod_type_bash, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ basic_info()

void item::basic_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1458 of file item.cpp.

1460{
1462 info.emplace_back( "BASE", string_format( _( "<stat>Origin: %s</stat>" ),
1463 enumerate_as_string( type->src.begin(),
1464 type->src.end(), []( const std::pair<itype_id, mod_id> &source ) {
1465 return string_format( "'%s'", source.second->name() );
1468 }
1470 info.emplace_back( "BASE", colorize( string_format( "[%s]", type->get_id() ), c_light_blue ) );
1472 }
1473
1474 const std::string space = " ";
1475 if( parts->test( iteminfo_parts::BASE_MATERIAL ) ) {
1476 const std::vector<const material_type *> mat_types = made_of_types();
1477 if( !mat_types.empty() ) {
1478 const std::string material_list = enumerate_as_string( mat_types.begin(), mat_types.end(),
1479 []( const material_type * material ) {
1480 return string_format( "<stat>%s</stat>", material->name() );
1482 info.push_back( iteminfo( "BASE", string_format( _( "Material: %s" ), material_list ) ) );
1483 }
1484 }
1485 if( parts->test( iteminfo_parts::BASE_VOLUME ) ) {
1486 int converted_volume_scale = 0;
1487 const double converted_volume = round_up( convert_volume( volume().value(),
1488 &converted_volume_scale ) * batch, 3 );
1490 if( converted_volume_scale != 0 ) {
1492 }
1493 info.push_back( iteminfo( "BASE", _( "Volume: " ),
1494 string_format( "<num> %s", volume_units_abbr() ),
1495 f, converted_volume ) );
1496 }
1497 if( parts->test( iteminfo_parts::BASE_WEIGHT ) ) {
1498 info.push_back( iteminfo( "BASE", space + _( "Weight: " ),
1499 string_format( "<num> %s", weight_units() ),
1501 convert_weight( weight() ) * batch ) );
1502 }
1503 if( !owner.is_null() ) {
1504 info.push_back( iteminfo( "BASE", string_format( _( "Owner: %s" ),
1505 _( get_owner_name() ) ) ) );
1506 }
1507 if( parts->test( iteminfo_parts::BASE_CATEGORY ) ) {
1508 info.push_back( iteminfo( "BASE", _( "Category: " ),
1509 "<header>" + get_category().name() + "</header>" ) );
1510 }
1511 if( !type->weapon_category.empty() && parts->test( iteminfo_parts::WEAPON_CATEGORY ) ) {
1512 const std::string weapon_categories = enumerate_as_string( type->weapon_category.begin(),
1513 type->weapon_category.end(), [&]( const weapon_category_id & elem ) {
1514 return elem->name().translated();
1516 info.push_back( iteminfo( "BASE", _( "Weapon Category: " ),
1517 "<header>" + weapon_categories + "</header>" ) );
1518 }
1519
1520 if( parts->test( iteminfo_parts::DESCRIPTION ) ) {
1522 const std::map<std::string, std::string>::const_iterator idescription =
1523 item_vars.find( "description" );
1524 const std::optional<translation> snippet = SNIPPET.get_snippet_by_id( snip_id );
1525 if( snippet.has_value() ) {
1526 // Just use the dynamic description
1527 info.push_back( iteminfo( "DESCRIPTION", snippet.value().translated() ) );
1528 } else if( idescription != item_vars.end() ) {
1529 info.push_back( iteminfo( "DESCRIPTION", idescription->second ) );
1530 } else {
1531 if( has_flag( "MAGIC_FOCUS" ) ) {
1532 info.push_back( iteminfo( "DESCRIPTION",
1533 _( "This item is a <info>magical focus</info>. "
1534 "You can cast spells with it in your hand." ) ) );
1535 }
1536 if( is_craft() ) {
1537 const std::string desc = _( "This is an in progress %s. "
1538 "It is %d percent complete." );
1539 const int percent_progress = item_counter / 100000;
1540 info.push_back( iteminfo( "DESCRIPTION", string_format( desc,
1541 craft_data_->making->result_name(),
1542 percent_progress ) ) );
1543 } else {
1544 info.push_back( iteminfo( "DESCRIPTION", type->description.translated() ) );
1545 }
1546 }
1548 }
1549
1551
1552 if( parts->test( iteminfo_parts::BASE_REQUIREMENTS ) ) {
1553 // Display any minimal stat or skill requirements for the item
1554 std::vector<std::string> req;
1555 if( get_min_str() > 0 ) {
1556 avatar &viewer = get_avatar();
1557 if( has_flag( flag_STR_DRAW ) && ranged::get_str_draw_penalty( *this, viewer ) < 1.0f ) {
1558 if( ranged::get_str_draw_penalty( *this, viewer ) < 0.5f ) {
1559 req.push_back( string_format( _( "%s %d <color_magenta>(Can't use!)</color>" ), _( "strength" ),
1560 get_min_str() ) );
1561 } else if( ranged::get_str_draw_penalty( *this, viewer ) < 0.75f ) {
1562 req.push_back( string_format( "%s %d <color_red>(Damage/Range 0.5x, Dispersion 2.0x)</color>",
1563 _( "strength" ), get_min_str() ) );
1564 } else {
1565 req.push_back( string_format( "%s %d <color_yellow>(Damage/Range 0.75x)</color>", _( "strength" ),
1566 get_min_str() ) );
1567 }
1568 } else {
1569 req.push_back( string_format( "%s %d", _( "strength" ), get_min_str() ) );
1570 }
1571 }
1572 if( type->min_dex > 0 ) {
1573 req.push_back( string_format( "%s %d", _( "dexterity" ), type->min_dex ) );
1574 }
1575 if( type->min_int > 0 ) {
1576 req.push_back( string_format( "%s %d", _( "intelligence" ), type->min_int ) );
1577 }
1578 if( type->min_per > 0 ) {
1579 req.push_back( string_format( "%s %d", _( "perception" ), type->min_per ) );
1580 }
1581 for( const std::pair<const skill_id, int> sk : sorted_lex( type->min_skills ) ) {
1582 req.push_back( string_format( "%s %d", skill_id( sk.first )->name(), sk.second ) );
1583 }
1584 if( !req.empty() ) {
1585 info.emplace_back( "BASE", _( "<bold>Minimum requirements</bold>:" ) );
1586 info.emplace_back( "BASE", enumerate_as_string( req ) );
1588 }
1589 }
1590
1591 if( has_var( "contained_name" ) && parts->test( iteminfo_parts::BASE_CONTENTS ) ) {
1592 info.push_back( iteminfo( "BASE", string_format( _( "Contains: %s" ),
1593 get_var( "contained_name" ) ) ) );
1594 }
1595 if( count_by_charges() && !is_food() && !is_medication() &&
1596 parts->test( iteminfo_parts::BASE_AMOUNT ) ) {
1597 info.push_back( iteminfo( "BASE", _( "Amount: " ), "<num>", iteminfo::no_flags,
1598 charges * batch ) );
1599 }
1600 if( debug && parts->test( iteminfo_parts::BASE_DEBUG ) ) {
1601 if( g != nullptr ) {
1602 info.push_back( iteminfo( "BASE", string_format( "itype_id: %s",
1603 typeId().c_str() ) ) );
1604 info.push_back( iteminfo( "BASE", _( "age (hours): " ), "", iteminfo::lower_is_better,
1605 to_hours<int>( age() ) ) );
1606 info.push_back( iteminfo( "BASE", _( "charges: " ), "", iteminfo::lower_is_better,
1607 charges ) );
1608 info.push_back( iteminfo( "BASE", _( "damage: " ), "", iteminfo::lower_is_better,
1609 damage_ ) );
1610 info.push_back( iteminfo( "BASE", _( "active: " ), "", iteminfo::lower_is_better,
1611 active ) );
1612 info.push_back( iteminfo( "BASE", _( "burn: " ), "", iteminfo::lower_is_better,
1613 burnt ) );
1614 const std::string tags_listed = enumerate_as_string( item_tags, enumeration_conjunction::none );
1615 info.push_back( iteminfo( "BASE", string_format( _( "tags: %s" ), tags_listed ) ) );
1616 for( auto const &imap : item_vars ) {
1617 info.push_back( iteminfo( "BASE",
1618 string_format( _( "item var: %s, %s" ), imap.first,
1619 imap.second ) ) );
1620 }
1621
1622 const item *food = get_food();
1623 if( food && food->goes_bad() ) {
1624 info.push_back( iteminfo( "BASE", _( "age (turns): " ),
1626 to_turns<int>( food->age() ) ) );
1627 info.push_back( iteminfo( "BASE", _( "rot (turns): " ),
1629 to_turns<int>( food->rot ) ) );
1630 info.push_back( iteminfo( "BASE", space + _( "max rot (turns): " ),
1632 to_turns<int>( food->get_shelf_life() ) ) );
1633 info.push_back( iteminfo( "BASE", _( "last rot: " ),
1635 to_turn<int>( food->last_rot_check ) ) );
1636 }
1637 }
1638 }
1639}
bool display_object_ids
Display internal IDs for items, furniture, terrain and monsters.
bool display_mod_source
Display mod source for items, furniture, terrain and monsters.
double get_var(const std::string &name, double default_value) const
Definition: item.cpp:1030
int burnt
Definition: item.h:2207
int get_min_str() const
Definition: item.cpp:10044
bool has_var(const std::string &name) const
Whether the variable is defined at all.
Definition: item.cpp:1075
time_duration age() const
Definition: item.cpp:10005
time_duration rot
Accumulated rot, expressed as time the item has been in standard temperature.
Definition: item.h:2227
faction_id owner
Definition: item.h:2233
bool is_medication() const
Definition: item.cpp:6598
time_duration get_shelf_life() const
Get the shelf life of the item.
Definition: item.cpp:5519
int damage_
Definition: item.h:2236
item * get_food()
Definition: item.cpp:6642
const item_category & get_category() const
Definition: item.cpp:8691
FlagsSetType item_tags
Definition: item.h:2171
std::string get_owner_name() const
Definition: item.cpp:1261
std::optional< translation > get_snippet_by_id(const snippet_id &id) const
Returns the snippet referenced by the id, or std::nullopt if there is no snippet with such id.
std::string translated(int num=1) const
Returns raw string if no translation is needed, otherwise returns the translated string.
std::string colorize(const std::string &text, const nc_color &color)
Definition: color.cpp:669
#define c_light_blue
Definition: color.h:29
std::unique_ptr< game > g
Definition: game.cpp:283
static const std::string flag_STR_DRAW("STR_DRAW")
std::vector< material_type > material_list
Definition: material.h:23
float get_str_draw_penalty(const item &it, const Character &p)
Penalties potentially incurred by STR_DRAW weapons.
Definition: ranged.cpp:1022
std::string enumerate_as_string(const _Container &values, enumeration_conjunction conj=enumeration_conjunction::and_)
Definition: output.h:637
std::vector< std::pair< K, V > > sorted_lex(Col col)
Returns vector sorted by lexicographic order of string_id.
@ is_three_decimal
Print as decimal with three points of precision.
Definition: item.h:146
int min_dex
Definition: itype.h:938
std::set< weapon_category_id > weapon_category
Definition: itype.h:905
int min_int
Definition: itype.h:939
int min_per
Definition: itype.h:940
translation description
Definition: itype.h:908
std::map< skill_id, int > min_skills
Definition: itype.h:936
std::vector< std::pair< itype_id, mod_id > > src
Definition: itype.h:841

References _, active, age(), arrow, BASE_AMOUNT, BASE_CATEGORY, BASE_CONTENTS, BASE_DEBUG, BASE_ID, BASE_MATERIAL, BASE_MOD_SRC, BASE_REQUIREMENTS, BASE_VOLUME, BASE_WEIGHT, burnt, c_light_blue, charges, colorize(), convert_volume(), convert_weight(), count_by_charges(), craft_data_, damage_, debug, DESCRIPTION, itype::description, display_mod_source, display_object_ids, enumerate_as_string(), flag_STR_DRAW(), g, get_avatar(), get_category(), get_food(), itype::get_id(), get_min_str(), get_owner_name(), get_shelf_life(), snippet_library::get_snippet_by_id(), ranged::get_str_draw_penalty(), get_var(), goes_bad(), has_flag(), has_var(), info(), insert_separation_line(), is_craft(), iteminfo::is_decimal, is_food(), is_medication(), string_id< T >::is_null(), iteminfo::is_three_decimal, item_counter, item_tags, item_vars, last_rot_check, iteminfo::lower_is_better, made_of_types(), itype::min_dex, itype::min_int, itype::min_per, itype::min_skills, om_direction::name(), iteminfo::no_flags, iteminfo::no_newline, none, owner, rot, round_up(), skill_id, snip_id, SNIPPET, sorted_lex(), sign::space, itype::src, string_format(), iteminfo_query::test(), translation::translated(), type, typeId(), volume(), volume_units_abbr(), WEAPON_CATEGORY, itype::weapon_category, weight(), and weight_units().

Referenced by info().

◆ battery_info()

void item::battery_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3062 of file item.cpp.

3064{
3065 if( !is_battery() ) {
3066 return;
3067 }
3068
3069 std::string info_string;
3070 if( type->battery->max_capacity < 1_kJ ) {
3071 info_string = string_format( _( "<bold>Capacity</bold>: %dJ" ),
3072 to_joule( type->battery->max_capacity ) );
3073 } else if( type->battery->max_capacity >= 1_kJ ) {
3074 info_string = string_format( _( "<bold>Capacity</bold>: %dkJ" ),
3075 to_kilojoule( type->battery->max_capacity ) );
3076 }
3078 info.emplace_back( "BATTERY", info_string );
3079}
bool is_battery() const
Definition: item.cpp:6562
std::string info_string() const
As info, but as a string rather than a vector of properties.
Definition: item.cpp:4066
constexpr value_type to_joule(const quantity< value_type, energy_in_joule_tag > &v)
Definition: units_energy.h:40
cata::value_ptr< islot_battery > battery
Definition: itype.h:862

References _, itype::battery, info(), info_string(), insert_separation_line(), is_battery(), string_format(), units::to_joule(), units::to_kilojoule(), and type.

Referenced by info().

◆ bionic_info()

void item::bionic_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3275 of file item.cpp.

3277{
3278 if( !is_bionic() ) {
3279 return;
3280 }
3281
3282 // TODO: Unhide when enforcing limits
3283 if( get_option < bool >( "CBM_SLOTS_ENABLED" )
3285 info.push_back( iteminfo( "DESCRIPTION", list_occupied_bps( type->bionic->id,
3286 _( "This bionic is installed in the following body "
3287 "part(s):" ) ) ) );
3288 }
3290
3291 const bionic_id bid = type->bionic->id;
3292 const std::vector<itype_id> &fuels = bid->fuel_opts;
3293 if( !fuels.empty() ) {
3294 const int &fuel_numb = fuels.size();
3295
3296 info.push_back( iteminfo( "DESCRIPTION",
3297 vgettext( "* This bionic can produce power from the following fuel: ",
3298 "* This bionic can produce power from the following fuels: ",
3299 fuel_numb ) + enumerate_as_string( fuels.begin(),
3300 fuels.end(), []( const itype_id & id ) -> std::string { return "<info>" + id->nname( 1 ) + "</info>"; } ) ) );
3301 }
3302
3304
3305 if( bid->capacity > 0_J ) {
3306 info.push_back( iteminfo( "CBM", _( "<bold>Power Capacity</bold>:" ), _( " <num> J" ),
3308 units::to_joule( bid->capacity ) ) );
3309 }
3310
3312
3313 if( !bid->encumbrance.empty() ) {
3314 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Encumbrance</bold>: " ),
3316 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->encumbrance ) ) {
3317 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3318 " <num> ", iteminfo::no_newline, element.second ) );
3319 }
3320 }
3321
3322 if( !bid->env_protec.empty() ) {
3323 info.push_back( iteminfo( "DESCRIPTION",
3324 bid->activated ? _( "<bold>Environmental Protection (activated)</bold>: " ) :
3325 _( "<bold>Environmental Protection</bold>: " ),
3327 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->env_protec ) ) {
3328 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3329 " <num> ", iteminfo::no_newline, element.second ) );
3330 }
3331 }
3332
3333 if( !bid->bash_protec.empty() ) {
3334 info.push_back( iteminfo( "DESCRIPTION",
3335 _( "<bold>Bash Protection</bold>: " ),
3337 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->bash_protec ) ) {
3338 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3339 " <num> ", iteminfo::no_newline, element.second ) );
3340 }
3341 }
3342
3343 if( !bid->cut_protec.empty() ) {
3344 info.push_back( iteminfo( "DESCRIPTION",
3345 _( "<bold>Cut Protection</bold>: " ),
3347 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->cut_protec ) ) {
3348 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3349 " <num> ", iteminfo::no_newline, element.second ) );
3350 }
3351 }
3352
3353 if( !bid->bullet_protec.empty() ) {
3354 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Ballistic Protection</bold>: " ),
3356 for( const auto &element : bid->bullet_protec ) {
3357 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3358 " <num> ", iteminfo::no_newline, element.second ) );
3359 }
3360 }
3361
3362 if( !bid->stat_bonus.empty() ) {
3363 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Stat Bonus</bold>: " ),
3365 for( const auto &element : bid->stat_bonus ) {
3366 info.push_back( iteminfo( "CBM", get_stat_name( element.first ), " <num> ",
3367 iteminfo::no_newline, element.second ) );
3368 }
3369 }
3370
3371 const units::mass weight_bonus = bid->weight_capacity_bonus;
3372 const float weight_modif = bid->weight_capacity_modifier;
3373 if( weight_modif != 1 ) {
3374 std::string modifier;
3375 if( weight_modif < 1 ) {
3376 modifier = "<num><bad>x</bad>";
3377 } else {
3378 modifier = "<num><color_light_green>x</color>";
3379 }
3380 info.push_back( iteminfo( "CBM",
3381 _( "<bold>Weight capacity modifier</bold>: " ), modifier,
3383 weight_modif ) );
3384 }
3385 if( weight_bonus != 0_gram ) {
3386 std::string bonus;
3387 if( weight_bonus < 0_gram ) {
3388 bonus = string_format( "<num> <bad>%s</bad>", weight_units() );
3389 } else {
3390 bonus = string_format( "<num> <color_light_green>%s</color>", weight_units() );
3391 }
3392 info.push_back( iteminfo( "CBM", _( "<bold>Weight capacity bonus</bold>: " ), bonus,
3394 convert_weight( weight_bonus ) ) );
3395 }
3396}
std::string list_occupied_bps(const bionic_id &bio_id, const std::string &intro, const bool each_bp_on_new_line)
Definition: bionics.cpp:2542
std::string body_part_name_as_heading(body_part bp, int number)
Returns the name of the body parts in a context where the name is used as a heading or title e....
Definition: bodypart.cpp:343
std::string get_stat_name(character_stat Stat)
Get translated name of a stat.
Definition: character.cpp:7737
bool is_bionic() const
Definition: item.cpp:6552
std::map< bodypart_str_id, int > cut_protec
Amount of cut protection offered by this bionic.
Definition: bionics.h:88
units::energy capacity
Power bank size.
Definition: bionics.h:49
bool activated
Is true if a bionic is an active instead of a passive bionic.
Definition: bionics.h:53
std::map< character_stat, int > stat_bonus
Map of stats and their corresponding bonuses passively granted by a bionic.
Definition: bionics.h:63
std::vector< itype_id > fuel_opts
Fuel types that can be used by this bionic.
Definition: bionics.h:67
float weight_capacity_modifier
Factor modifiying weight capacity.
Definition: bionics.h:59
units::mass weight_capacity_bonus
Bonus to weight capacity.
Definition: bionics.h:61
std::map< bodypart_str_id, int > encumbrance
Body part encumbered by this bionic, mapped to the amount of encumbrance caused.
Definition: bionics.h:99
std::map< bodypart_str_id, int > bullet_protec
Amount of bullet protection offered by this bionic.
Definition: bionics.h:90
std::map< bodypart_str_id, int > bash_protec
Amount of bash protection offered by this bionic.
Definition: bionics.h:86
std::map< bodypart_str_id, int > env_protec
Amount of environemental protection offered by this bionic.
Definition: bionics.h:84
cata::value_ptr< islot_bionic > bionic
Definition: itype.h:863
const char * vgettext(const char *msgid, const char *msgid_plural, size_t n)

References _, bionic_data::activated, bionic_data::bash_protec, itype::bionic, body_part_name_as_heading(), bionic_data::bullet_protec, bionic_data::capacity, convert_weight(), bionic_data::cut_protec, DESCRIPTION_CBM_SLOTS, bionic_data::encumbrance, enumerate_as_string(), bionic_data::env_protec, bionic_data::fuel_opts, get_stat_name(), info(), insert_separation_line(), is_bionic(), iteminfo::is_decimal, list_occupied_bps(), iteminfo::no_newline, sorted_lex(), bionic_data::stat_bonus, string_format(), iteminfo_query::test(), units::to_joule(), type, vgettext(), bionic_data::weight_capacity_bonus, bionic_data::weight_capacity_modifier, and weight_units().

Referenced by final_info().

◆ birthday()

◆ bonus_from_enchantments()

double item::bonus_from_enchantments ( const Character owner,
double  base,
enchant_vals::mod  value,
bool  round = false 
) const

Calculate bonus from enchantments that affect this item only.

Definition at line 6987 of file item.cpp.

6989{
6990 double add = 0.0;
6991 double mul = 0.0;
6992 for( const enchantment &ench : get_enchantments() ) {
6993 if( ench.is_active( owner, *this ) ) {
6994 add += ench.get_value_add( value );
6995 mul += ench.get_value_multiply( value );
6996 }
6997 }
6998 // TODO: this part duplicates enchantment::calc_bonus()
6999 double ret = add + base * mul;
7000 if( round ) {
7001 ret = trunc( ret );
7002 }
7003 return ret;
7004}
const std::vector< enchantment > & get_enchantments() const
Definition: item.cpp:6978
type add(type dir1, type dir2)
Returns a sum of two numbers.
Definition: overmap.cpp:4193

References om_direction::add(), get_enchantments(), owner, and cata::hash64_detail::ret.

Referenced by item_armor_enchantment_adjust().

◆ bonus_from_enchantments_wielded()

double item::bonus_from_enchantments_wielded ( double  base,
enchant_vals::mod  value,
bool  round = false 
) const

Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantments' conditions are satisfied.

Definition at line 7006 of file item.cpp.

7008{
7009 double add = 0.0;
7010 double mul = 0.0;
7011 for( const enchantment &ench : get_enchantments() ) {
7012 if( ench.is_active_when_wielded() ) {
7013 add += ench.get_value_add( value );
7014 mul += ench.get_value_multiply( value );
7015 }
7016 }
7017 // TODO: this part duplicates enchantment::calc_bonus()
7018 double ret = add + base * mul;
7019 if( round ) {
7020 ret = trunc( ret );
7021 }
7022 return ret;
7023}

References om_direction::add(), get_enchantments(), and cata::hash64_detail::ret.

Referenced by attack_cost(), and damage_melee().

◆ book_info()

void item::book_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2897 of file item.cpp.

2899{
2900 if( !is_book() ) {
2901 return;
2902 }
2903
2904 Character &character = get_player_character();
2905
2907 const islot_book &book = *type->book;
2908 // Some things about a book you CAN tell by it's cover.
2909 if( !book.skill && !type->can_use( "MA_MANUAL" ) && parts->test( iteminfo_parts::BOOK_SUMMARY ) ) {
2910 info.push_back( iteminfo( "BOOK", _( "Just for fun." ) ) );
2911 }
2912 if( type->can_use( "MA_MANUAL" ) && parts->test( iteminfo_parts::BOOK_SUMMARY ) ) {
2913 info.push_back( iteminfo( "BOOK",
2914 _( "Some sort of <info>martial arts training "
2915 "manual</info>." ) ) );
2916 const matype_id style_to_learn = martial_art_learned_from( *type );
2917 info.push_back( iteminfo( "BOOK",
2918 string_format( _( "You can learn <info>%s</info> style "
2919 "from it." ), style_to_learn->name ) ) );
2920 info.push_back( iteminfo( "BOOK",
2921 string_format( _( "This fighting style is <info>%s</info> "
2922 "to learn." ),
2923 martialart_difficulty( style_to_learn ) ) ) );
2924 info.push_back( iteminfo( "BOOK",
2925 string_format( _( "It'd be easier to master if you'd have "
2926 "skill expertise in <info>%s</info>." ),
2927 style_to_learn->primary_skill->name() ) ) );
2928 }
2929 if( book.req == 0 && parts->test( iteminfo_parts::BOOK_REQUIREMENTS_BEGINNER ) ) {
2930 info.push_back( iteminfo( "BOOK", _( "It can be <info>understood by "
2931 "beginners</info>." ) ) );
2932 }
2933 avatar &you = get_avatar();
2934 if( !you.has_identified( typeId() ) && parts->test( iteminfo_parts::BOOK_UNREAD ) ) {
2935 info.push_back( iteminfo( "BOOK",
2936 _( "You have <info>never read</info> this book." ) ) );
2937 }
2938 if( book.skill ) {
2939 const SkillLevel &skill = you.get_skill_level_object( book.skill );
2940 if( skill.can_train() && parts->test( iteminfo_parts::BOOK_SKILLRANGE_MAX ) ) {
2941 const std::string skill_name = book.skill->name();
2942 std::string fmt = string_format( _( "Can bring your <info>%s skill to</info> "
2943 "<num>." ), skill_name );
2944 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, book.level ) );
2945 fmt = string_format( _( "Your current <stat>%s skill</stat> is <num>." ),
2946 skill_name );
2947 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, skill.level() ) );
2948 }
2949
2950 if( book.req != 0 && parts->test( iteminfo_parts::BOOK_SKILLRANGE_MIN ) ) {
2951 const std::string fmt = string_format(
2952 _( "<info>Requires %s level</info> <num> to "
2953 "understand." ), book.skill.obj().name() );
2954 info.push_back( iteminfo( "BOOK", "", fmt,
2956 }
2957 }
2958
2959 if( book.intel != 0 && parts->test( iteminfo_parts::BOOK_REQUIREMENTS_INT ) ) {
2960 info.push_back( iteminfo( "BOOK", "",
2961 _( "Requires <info>intelligence of</info> <num> to easily "
2962 "read." ), iteminfo::lower_is_better, book.intel ) );
2963 }
2964 if( character_funcs::get_book_fun_for( character, *this ) != 0 &&
2966 info.push_back( iteminfo( "BOOK", "",
2967 _( "Reading this book affects your morale by <num>" ),
2969 }
2971 std::string fmt = vgettext(
2972 "A chapter of this book takes <num> <info>minute to "
2973 "read</info>.",
2974 "A chapter of this book takes <num> <info>minutes to "
2975 "read</info>.", book.time );
2976 if( type->use_methods.count( "MA_MANUAL" ) ) {
2977 fmt = vgettext(
2978 "<info>A training session</info> with this book takes "
2979 "<num> <info>minute</info>.",
2980 "<info>A training session</info> with this book takes "
2981 "<num> <info>minutes</info>.", book.time );
2982 }
2983 info.push_back( iteminfo( "BOOK", "", fmt,
2985 }
2986
2987 if( book.chapters > 0 && parts->test( iteminfo_parts::BOOK_NUMUNREADCHAPTERS ) ) {
2988 const int unread = get_remaining_chapters( you );
2989 std::string fmt = vgettext( "This book has <num> <info>unread chapter</info>.",
2990 "This book has <num> <info>unread chapters</info>.",
2991 unread );
2992 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, unread ) );
2993 }
2994
2995 std::vector<std::string> recipe_list;
2996 for( const islot_book::recipe_with_description_t &elem : book.recipes ) {
2997 const bool knows_it = you.knows_recipe( elem.recipe );
2998 const bool can_learn = you.get_skill_level( elem.recipe->skill_used ) >= elem.skill_level;
2999 // If the player knows it, they recognize it even if it's not clearly stated.
3000 if( elem.is_hidden() && !knows_it ) {
3001 continue;
3002 }
3003 if( knows_it ) {
3004 // In case the recipe is known, but has a different name in the book, use the
3005 // real name to avoid confusing the player.
3006 const std::string name = elem.recipe->result_name();
3007 recipe_list.push_back( "<bold>" + name + "</bold>" );
3008 } else if( !can_learn ) {
3009 recipe_list.push_back( "<color_brown>" + elem.name + "</color>" );
3010 } else {
3011 recipe_list.push_back( "<dark>" + elem.name + "</dark>" );
3012 }
3013 }
3014
3015 if( !recipe_list.empty() && parts->test( iteminfo_parts::DESCRIPTION_BOOK_RECIPES ) ) {
3016 std::string recipe_line =
3017 string_format( vgettext( "This book contains %1$d crafting recipe: %2$s",
3018 "This book contains %1$d crafting recipes: %2$s",
3019 recipe_list.size() ),
3020 recipe_list.size(), enumerate_as_string( recipe_list ) );
3021
3023 info.push_back( iteminfo( "DESCRIPTION", recipe_line ) );
3024 }
3025
3026 if( recipe_list.size() != book.recipes.size() &&
3028 info.push_back( iteminfo( "DESCRIPTION",
3029 _( "It might help you figuring out some <good>more "
3030 "recipes</good>." ) ) );
3031 }
3032}
Character & get_player_character()
Definition: character.cpp:400
SkillLevel & get_skill_level_object(const skill_id &ident)
Definition: character.cpp:3335
bool knows_recipe(const recipe *rec) const
int get_skill_level(const skill_id &ident) const
Definition: character.cpp:3340
int level() const
Definition: skill.h:125
bool can_train() const
Definition: skill.cpp:311
std::string name() const
Definition: skill.h:68
bool has_identified(const itype_id &item_id) const
Note that we've read a book at least once.
Definition: avatar.cpp:953
bool is_book() const
Definition: item.cpp:6709
int get_remaining_chapters(const Character &ch) const
Get the number of unread chapters.
Definition: item.cpp:7097
translation name
Definition: martialarts.h:270
skill_id primary_skill
Definition: martialarts.h:274
std::string result_name() const
Definition: recipe.cpp:612
skill_id skill_used
Definition: recipe.h:109
@ BOOK_REQUIREMENTS_BEGINNER
@ DESCRIPTION_BOOK_ADDITIONAL_RECIPES
std::string martialart_difficulty(const matype_id &mstyle)
matype_id martial_art_learned_from(const itype &type)
Definition: martialarts.cpp:90
int get_book_fun_for(const Character &ch, const item &book)
Returns enjoyability value of a book for given character.
What recipes can be learned from this book.
Definition: itype.h:359
std::string name
The name for the recipe as it appears in the book.
Definition: itype.h:371
int skill_level
The skill level required to learn the recipe.
Definition: itype.h:367
const class recipe * recipe
The recipe that can be learned (never null).
Definition: itype.h:363
int level
The skill level the book provides.
Definition: itype.h:334
int intel
Intelligence required to read it.
Definition: itype.h:346
skill_id skill
Which skill it upgrades, if any.
Definition: itype.h:326
int req
The skill level required to understand it.
Definition: itype.h:338
recipe_list_t recipes
Definition: itype.h:384
int time
How long in minutes it takes to read.
Definition: itype.h:351
int chapters
Fun books have chapters; after all are read, the book is less fun.
Definition: itype.h:355
@ show_plus
Use a + sign for positive values.
Definition: item.h:150
cata::value_ptr< islot_book > book
Definition: itype.h:854
std::map< std::string, use_function > use_methods
Actions an instance can perform (if any) indexed by action type.
Definition: itype.h:925

References _, itype::book, BOOK_MORALECHANGE, BOOK_NUMUNREADCHAPTERS, BOOK_REQUIREMENTS_BEGINNER, BOOK_REQUIREMENTS_INT, BOOK_SKILLRANGE_MAX, BOOK_SKILLRANGE_MIN, BOOK_SUMMARY, BOOK_TIMEPERCHAPTER, BOOK_UNREAD, SkillLevel::can_train(), itype::can_use(), islot_book::chapters, DESCRIPTION_BOOK_ADDITIONAL_RECIPES, DESCRIPTION_BOOK_RECIPES, enumerate_as_string(), get_avatar(), character_funcs::get_book_fun_for(), get_player_character(), get_remaining_chapters(), Character::get_skill_level(), Character::get_skill_level_object(), avatar::has_identified(), info(), insert_separation_line(), islot_book::intel, is_book(), islot_book::recipe_with_description_t::is_hidden(), Character::knows_recipe(), islot_book::level, SkillLevel::level(), iteminfo::lower_is_better, martial_art_learned_from(), martialart_difficulty(), islot_book::recipe_with_description_t::name, martialart::name, Skill::name(), om_direction::name(), iteminfo::no_flags, string_id< T >::obj(), martialart::primary_skill, islot_book::recipe_with_description_t::recipe, islot_book::recipes, islot_book::req, recipe::result_name(), iteminfo::show_plus, islot_book::skill, islot_book::recipe_with_description_t::skill_level, recipe::skill_used, string_format(), iteminfo_query::test(), islot_book::time, type, typeId(), itype::use_methods, and vgettext().

Referenced by info().

◆ brewing_results()

const std::vector< itype_id > & item::brewing_results ( ) const

The results of fermenting this item.

Definition at line 5951 of file item.cpp.

5952{
5953 static const std::vector<itype_id> nulresult{};
5954 return is_brewable() ? type->brewable->results : nulresult;
5955}
bool is_brewable() const
Definition: item.cpp:6603
cata::value_ptr< islot_brewable > brewable
Definition: itype.h:851

References itype::brewable, is_brewable(), and type.

Referenced by final_info(), and iexamine::fvat_full().

◆ brewing_time()

time_duration item::brewing_time ( ) const

Time for this item to be fully fermented.

Definition at line 5946 of file item.cpp.

5947{
5948 return is_brewable() ? type->brewable->time : 0_turns;
5949}

References itype::brewable, is_brewable(), and type.

Referenced by final_info(), and iexamine::fvat_full().

◆ bullet_resist()

int item::bullet_resist ( bool  to_self = false) const

Definition at line 6098 of file item.cpp.

6099{
6100 if( is_null() ) {
6101 return 0;
6102 }
6103
6104 const int base_thickness = get_thickness();
6105 float resist = 0;
6107 int eff_thickness = 1;
6108
6109 // base resistance
6110 // Don't give reinforced items +armor, just more resistance to ripping
6111 const int dmg = damage_level( 4 );
6112 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6113 eff_thickness = std::max( 1, base_thickness - eff_damage );
6114
6115 const std::vector<const material_type *> mat_types = made_of_types();
6116 if( !mat_types.empty() ) {
6117 for( const material_type *mat : mat_types ) {
6118 resist += mat->bullet_resist();
6119 }
6120 // Average based on number of materials.
6121 resist /= mat_types.size();
6122 }
6123
6124 return std::lround( ( resist * eff_thickness ) + mod );
6125}
@ clothing_mod_type_bullet
Definition: clothing_mod.h:21

References clothing_mod_type_bullet, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ burn()

bool item::burn ( fire_data frd)

Burns the item.

Returns true if the item was destroyed.

Definition at line 8284 of file item.cpp.

8285{
8286 float burn_added = simulate_burn( frd );
8287
8288 if( burn_added <= 0 ) {
8289 return false;
8290 }
8291
8292 if( count_by_charges() ) {
8293 if( type->volume == 0_ml ) {
8294 charges = 0;
8295 } else {
8297 ( 3.0 * type->volume ) );
8298 }
8299
8300 return charges <= 0;
8301 }
8302
8303 if( is_corpse() ) {
8304 const mtype *mt = get_mtype();
8305 if( active && mt != nullptr && burnt + burn_added > mt->hp &&
8306 !mt->burn_into.is_null() && mt->burn_into.is_valid() ) {
8307 corpse = &get_mtype()->burn_into.obj();
8308 // Delay rezing
8309 set_age( 0_turns );
8310 burnt = 0;
8311 return false;
8312 }
8313 }
8314
8315 burnt += roll_remainder( burn_added );
8316
8317 const int vol = base_volume() / units::legacy_volume_factor;
8318 return burnt >= vol * 3;
8319}
units::volume base_volume() const
Simplified, faster volume check for when processing time is important and exact volume is not.
Definition: item.cpp:5076
float simulate_burn(fire_data &frd) const
Calculate all burning calculations, but don't actually apply them to item.
Definition: item.cpp:8231
const mtype * get_mtype() const
Definition: item.cpp:6625
void set_age(const time_duration &age)
Definition: item.cpp:10010
bool is_valid() const
Returns whether this id is valid, that means whether it refers to an existing object.
Definition: achievement.cpp:67
static constexpr volume legacy_volume_factor
Definition: units_volume.h:50
int roll_remainder(double value)
Definition: rng.cpp:96
Definition: mtype.h:208
mtype_id burn_into
Definition: mtype.h:331
int hp
Definition: mtype.h:270

References active, base_volume(), mtype::burn_into, burnt, charges, corpse, count_by_charges(), get_mtype(), mtype::hp, is_corpse(), string_id< T >::is_null(), string_id< T >::is_valid(), units::legacy_volume_factor, string_id< T >::obj(), roll_remainder(), set_age(), simulate_burn(), itype::stack_size, type, and itype::volume.

Referenced by Character::absorb_hit().

◆ calc_rot()

time_duration item::calc_rot ( time_point  time,
int  temp 
) const

Returns rot of the item since last rot calculation.

This function should not be called directly. since it does not have all the needed checks or temperature calculations. If you need to calc rot of item call process_rot instead.

Parameters
timeTime point to which rot is calculated
tempTemperature at which the rot is calculated

Definition at line 5651 of file item.cpp.

5652{
5653 // Avoid needlessly calculating already rotten things. Corpses should
5654 // always rot away and food rots away at twice the shelf life. If the food
5655 // is in a sealed container they won't rot away, this avoids needlessly
5656 // calculating their rot in that case.
5657 if( !is_corpse() && get_relative_rot() > 2.0 ) {
5658 return time_duration::from_seconds( 0 );
5659 }
5660
5661 // rot modifier
5662 float factor = 1.0;
5663 if( is_corpse() && has_flag( flag_FIELD_DRESS ) ) {
5664 factor = 0.75;
5665 }
5666
5668 // simulation of different age of food at the start of the game and good/bad storage
5669 // conditions by applying starting variation bonus/penalty of +/- 20% of base shelf-life
5670 // positive = food was produced some time before calendar::start and/or bad storage
5671 // negative = food was stored in good conditions before calendar::start
5673 time_duration spoil_variation = get_shelf_life() * 0.2f;
5674 added_rot += rng( -spoil_variation, spoil_variation );
5675 }
5676
5677 time_duration time_delta = time - last_rot_check;
5678 added_rot += factor * time_delta / 1_hours * get_hourly_rotpoints_at_temp( temp ) * 1_turns;
5679 return added_rot;
5680}
A duration defined as a number of specific time units.
Definition: calendar.h:180
static constexpr time_duration from_seconds(const T t)
Definition: calendar.h:208
static const std::string flag_FIELD_DRESS("FIELD_DRESS")
int get_hourly_rotpoints_at_temp(const int temp)
Get the hourly rot for a given temperature from the precomputed table.
Definition: item.cpp:5635
@ time
Recharges slowly with time.

References flag_FIELD_DRESS(), time_duration::from_seconds(), get_hourly_rotpoints_at_temp(), get_relative_rot(), get_shelf_life(), has_flag(), is_corpse(), last_rot_check, rng(), calendar::start_of_cataclysm, and time.

Referenced by process_rot().

◆ can_contain() [1/2]

bool item::can_contain ( const item it) const

Can this item have given item/itype as content?

For example, airtight for gas, acidproof for acid etc.

Definition at line 7030 of file item.cpp.

7031{
7032 // TODO: Volume check
7033 return can_contain( *it.type );
7034}
bool can_contain(const item &it) const
Can this item have given item/itype as content?
Definition: item.cpp:7030

References can_contain(), and type.

Referenced by can_contain().

◆ can_contain() [2/2]

bool item::can_contain ( const itype tp) const

Definition at line 7036 of file item.cpp.

7037{
7038 if( !type->container ) {
7039 // TODO: Tools etc.
7040 return false;
7041 }
7042
7043 if( tp.phase == LIQUID && !type->container->watertight ) {
7044 return false;
7045 }
7046
7047 // TODO: Acid in waterskins
7048 return true;
7049}
@ LIQUID
Definition: enums.h:175
phase_id phase
Definition: itype.h:942

References itype::container, LIQUID, itype::phase, and type.

◆ can_holster()

bool item::can_holster ( const item obj,
bool  ignore = false 
) const

Checks if item is a holster and currently capable of storing obj.

Parameters
objobject that we want to holster
ignoreonly check item is compatible and ignore any existing contents

Definition at line 8877 of file item.cpp.

8878{
8879 if( !type->can_use( "holster" ) ) {
8880 return false; // item is not a holster
8881 }
8882
8883 const holster_actor *ptr = dynamic_cast<const holster_actor *>
8884 ( type->get_use( "holster" )->get_actor_ptr() );
8885 if( !ptr->can_holster( obj ) ) {
8886 return false; // item is not a suitable holster for obj
8887 }
8888
8889 if( !ignore && static_cast<int>( contents.num_item_stacks() ) >= ptr->multi ) {
8890 return false; // item is already full
8891 }
8892
8893 return true;
8894}
Holster a weapon.
Definition: iuse_actor.h:842
size_t num_item_stacks() const
returns the number of items stacks in contents each item that is not count_by_charges,...
const void * ptr(const T *p)
\rst Converts p to const void* for pointer formatting.

References itype::can_use(), contents, use_function::get_actor_ptr(), itype::get_use(), item_contents::num_item_stacks(), ptr(), and type.

◆ can_reload_with() [1/2]

bool item::can_reload_with ( const ammotype ammo) const

Returns true if this item can be reloaded with specified ammo type, ignoring currently loaded ammo.

Definition at line 6861 of file item.cpp.

6862{
6863 return is_reloadable_helper( ammo->default_ammotype(), false );
6864}
bool is_reloadable_helper(const itype_id &ammo, bool now) const
Helper for checking reloadability.
Definition: item.cpp:6876

References ammunition_type::default_ammotype(), and is_reloadable_helper().

Referenced by favorite_ammo_or_select(), avatar_funcs::gunmod_add(), and aim_activity_actor::load_RAS_weapon().

◆ can_reload_with() [2/2]

bool item::can_reload_with ( const itype_id ammo) const

Returns true if this item can be reloaded with specified ammo item, ignoring currently loaded ammo.

Definition at line 6866 of file item.cpp.

6867{
6868 return is_reloadable_helper( ammo, false );
6869}

References is_reloadable_helper().

◆ can_revive()

bool item::can_revive ( ) const

Whether this is a corpse that can be revived.

Definition at line 5957 of file item.cpp.

5958{
5959 return is_corpse() && corpse->has_flag( MF_REVIVES ) && damage() < max_damage() &&
5963}
int max_damage() const
Maximum amount of damage to an item (state before destroyed)
Definition: item.cpp:6216
static const std::string flag_QUARTERED("QUARTERED")
static const std::string flag_SKINNED("SKINNED")
static const std::string flag_FIELD_DRESS_FAILED("FIELD_DRESS_FAILED")
static const std::string flag_PULPED("PULPED")
@ MF_REVIVES
Definition: mtype.h:125
bool has_flag(m_flag flag) const
Definition: mtype.cpp:75

References corpse, damage(), flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_PULPED(), flag_QUARTERED(), flag_SKINNED(), has_flag(), mtype::has_flag(), is_corpse(), max_damage(), and MF_REVIVES.

Referenced by active_item_cache::add(), color_in_inventory(), has_rotten_away(), ready_to_revive(), active_item_cache::remove(), basecamp::start_relay_hide_site(), and basecamp::start_setup_hide_site().

◆ can_unload_liquid()

bool item::can_unload_liquid ( ) const

Returns true if not empty if it's liquid, it's not currently frozen in resealable container.

Definition at line 6850 of file item.cpp.

6851{
6852 if( is_container_empty() ) {
6853 return true;
6854 }
6855
6856 const item &cts = contents.front();
6857 bool cts_is_frozen_liquid = cts.made_of( LIQUID ) && cts.made_of( SOLID );
6858 return is_bucket() || !cts_is_frozen_liquid;
6859}
const std::vector< material_id > & made_of() const
The ids of all the materials this is made of.
Definition: item.cpp:6413
bool is_container_empty() const
Whether this item has no contents at all.
Definition: item.cpp:6837
bool is_bucket() const
Definition: item.cpp:6734
@ SOLID
Definition: enums.h:175

References contents, item_contents::front(), is_bucket(), is_container_empty(), LIQUID, made_of(), and SOLID.

Referenced by item_funcs::can_be_unloaded(), iexamine::keg(), and avatar_funcs::unload_item().

◆ casings_count()

int item::casings_count ( ) const

How many spent casings are contained within this item?

Definition at line 8090 of file item.cpp.

8091{
8092 int res = 0;
8093
8094 const_cast<item *>( this )->casings_handle( [&res]( item & ) {
8095 ++res;
8096 return false;
8097 } );
8098
8099 return res;
8100}
void casings_handle(const std::function< bool(item &)> &func)
Apply predicate to each contained spent casing removing it if predicate returns true.
Definition: item.cpp:8102

References casings_handle().

Referenced by item_funcs::can_be_unloaded(), and avatar_funcs::unload_item().

◆ casings_handle()

void item::casings_handle ( const std::function< bool(item &)> &  func)

Apply predicate to each contained spent casing removing it if predicate returns true.

Definition at line 8102 of file item.cpp.

8103{
8104 if( !is_gun() ) {
8105 return;
8106 }
8107
8108 contents.casings_handle( func );
8109}
void casings_handle(const std::function< bool(item &)> &func)

References item_contents::casings_handle(), contents, and is_gun().

Referenced by casings_count(), avatar_funcs::gunmod_remove(), reload(), and avatar_funcs::unload_item().

◆ charges_per_volume()

int item::charges_per_volume ( const units::volume vol) const

Number of (charges of) this item that fit into the given volume.

May return 0 if not even one charge fits into the volume. Only depends on the type of this item not on its current charge count.

For items not counted by charges, this returns vol / this->volume().

Definition at line 864 of file item.cpp.

865{
866 if( count_by_charges() ) {
867 if( type->volume == 0_ml ) {
868 debugmsg( "Item '%s' with zero volume", tname() );
869 return INFINITE_CHARGES;
870 }
871 // Type cast to prevent integer overflow with large volume containers like the cargo
872 // dimension
873 return vol * static_cast<int64_t>( type->stack_size ) / type->volume;
874 } else {
875 units::volume my_volume = volume();
876 if( my_volume == 0_ml ) {
877 debugmsg( "Item '%s' with zero volume", tname() );
878 return INFINITE_CHARGES;
879 }
880 return vol / my_volume;
881 }
882}
static const int INFINITE_CHARGES
Definition: item.h:2162

References count_by_charges(), debugmsg, INFINITE_CHARGES, itype::stack_size, tname(), type, volume(), and itype::volume.

Referenced by item_stack::amount_can_fit(), Character::can_feed_furnace_with(), vehicle_part::consume_energy(), display_name(), Character::feed_furnace_with(), activity_handlers::fill_liquid_do_turn(), Character::get_acquirable_energy(), get_remaining_capacity_for_liquid(), in_container(), Item_factory::migrate_item(), Item_modifier::modify(), vehicle::print_fuel_indicator(), advanced_inventory::query_charges(), and try_fuel_fire().

◆ chip_resistance()

int item::chip_resistance ( bool  worst = false) const

Returns resistance to being damaged by attack against the item itself.

Calculated from item's materials.

Parameters
worstIf this is true, the worst resistance is used. Otherwise the best one.

Definition at line 6192 of file item.cpp.

6193{
6194 int res = worst ? INT_MAX : INT_MIN;
6195 for( const material_type *mat : made_of_types() ) {
6196 const int val = mat->chip_resist();
6197 res = worst ? std::min( res, val ) : std::max( res, val );
6198 }
6199
6200 if( res == INT_MAX || res == INT_MIN ) {
6201 return 2;
6202 }
6203
6204 if( res <= 0 ) {
6205 return 0;
6206 }
6207
6208 return res;
6209}

References made_of_types().

Referenced by Character::handle_melee_wear().

◆ clear_vars()

void item::clear_vars ( )

Removes all item variables.

Definition at line 1085 of file item.cpp.

1086{
1087 item_vars.clear();
1088}

References item_vars.

Referenced by iuse::camera(), einkpc_download_memory_card(), and iuse::einktabletpc().

◆ color()

nc_color item::color ( ) const

Returns the default color of the item (e.g.

itype::color).

Definition at line 4910 of file item.cpp.

4911{
4912 if( is_null() ) {
4913 return c_black;
4914 }
4915 if( is_corpse() ) {
4916 return corpse->color;
4917 }
4918 return type->color;
4919}
#define c_black
Definition: color.h:17
nc_color color
Definition: itype.h:1006
nc_color color
Definition: mtype.h:261

References c_black, itype::color, mtype::color, corpse, is_corpse(), is_null(), and type.

Referenced by map::draw_maptile(), Character::pour_into(), and debug_menu::wishitem().

◆ color_in_inventory() [1/2]

nc_color item::color_in_inventory ( ) const

Returns the color of the item depending on usefulness for the player character, e.g.

differently if it its an unread book or a spoiling food item etc. This should only be used for displaying data, it should not affect game play.

Definition at line 4127 of file item.cpp.

4128{
4130}
nc_color color_in_inventory() const
Returns the color of the item depending on usefulness for the player character, e....
Definition: item.cpp:4127

References color_in_inventory(), and get_avatar().

Referenced by color_in_inventory(), colorized_item_name(), inventory_selector_preset::get_color(), read_inventory_preset::get_color(), avatar_funcs::gunmod_add(), game::list_items(), iuse::marloss_seed(), pickup::pick_up(), iuse::seed(), Character::takeoff(), and Character::will_eat().

◆ color_in_inventory() [2/2]

nc_color item::color_in_inventory ( const player p) const

Returns the color of the item depending on usefulness for the passed player, e.g.

differently if it its an unread book or a spoiling food item etc. This should only be used for displaying data, it should not affect game play.

Parameters
for_playerNPC or avatar which would read book.

Definition at line 4132 of file item.cpp.

4133{
4134 // Only item not otherwise colored gets colored as favorite
4136 if( type->can_use( "learn_spell" ) ) {
4137 const use_function *iuse = get_use( "learn_spell" );
4138 const learn_spell_actor *actor_ptr =
4139 static_cast<const learn_spell_actor *>( iuse->get_actor_ptr() );
4140 for( const std::string &spell_id_str : actor_ptr->spells ) {
4141 const spell_id sp_id( spell_id_str );
4142 if( p.magic->knows_spell( sp_id ) && !p.magic->get_spell( sp_id ).is_max_level() ) {
4143 ret = c_yellow;
4144 }
4145 if( !p.magic->knows_spell( sp_id ) && p.magic->can_learn_spell( p, sp_id ) ) {
4146 return c_light_blue;
4147 }
4148 }
4149 } else if( has_flag( flag_WET ) ) {
4150 ret = c_cyan;
4151 } else if( has_flag( flag_LITCIG ) ) {
4152 ret = c_red;
4153 } else if( is_armor() && p.has_trait( trait_WOOLALLERGY ) &&
4154 ( made_of( material_id( "wool" ) ) || has_own_flag( "wooled" ) ) ) {
4155 ret = c_red;
4156 } else if( is_filthy() || has_own_flag( "DIRTY" ) ) {
4157 ret = c_brown;
4158 } else if( is_bionic() ) {
4159 if( !p.has_bionic( type->bionic->id ) ) {
4160 ret = p.bionic_installation_issues( type->bionic->id ).empty() ? c_green : c_red;
4161 } else if( !has_fault( fault_bionic_nonsterile ) ) {
4162 ret = c_dark_gray;
4163 }
4164 } else if( has_flag( flag_LEAK_DAM ) && has_flag( flag_RADIOACTIVE ) && damage() > 0 ) {
4166 } else if( active && !is_food() && !is_food_container() && !is_corpse() ) {
4167 // Active items show up as yellow
4168 ret = c_yellow;
4169 } else if( is_corpse() && can_revive() ) {
4170 // Only reviving corpses are yellow
4171 ret = c_yellow;
4172 } else if( const item *food = get_food() ) {
4173 const bool preserves = type->container && type->container->preserves;
4174
4175 // Give color priority to allergy (allergy > inedible by freeze or other conditions)
4176 // TODO: refactor u.will_eat to let this section handle coloring priority without duplicating code.
4177 if( p.allergy_type( *food ) != morale_type( "morale_null" ) ) {
4178 return c_red;
4179 }
4180
4181 // Default: permafood, drugs
4182 // Brown: rotten (for non-saprophages) or non-rotten (for saprophages)
4183 // Dark gray: inedible
4184 // Red: morale penalty
4185 // Yellow: will rot soon
4186 // Cyan: will rot eventually
4187 const ret_val<edible_rating> rating = p.will_eat( *food );
4188 // TODO: More colors
4189 switch( rating.value() ) {
4192 if( preserves ) {
4193 // Nothing, canned food won't rot
4194 } else if( food->is_going_bad() ) {
4195 ret = c_yellow;
4196 } else if( food->goes_bad() ) {
4197 ret = c_cyan;
4198 }
4199 break;
4202 ret = c_dark_gray;
4203 break;
4207 ret = c_red;
4208 break;
4210 ret = c_brown;
4211 break;
4214 ret = c_pink;
4215 break;
4217 break;
4218 }
4219 } else if( is_gun() ) {
4220 // Guns are green if you are carrying ammo for them
4221 // ltred if you have ammo but no mags
4222 // Gun with integrated mag counts as both
4223 for( const ammotype &at : ammo_types() ) {
4224 // get_ammo finds uncontained ammo, find_ammo finds ammo in magazines
4225 bool has_ammo = !character_funcs::get_ammo_items( p, at ).empty() ||
4226 !character_funcs::find_ammo_items_or_mags( p, *this, false, -1 ).empty();
4227 bool has_mag = magazine_integral() ||
4228 !character_funcs::find_ammo_items_or_mags( p, *this, true, -1 ).empty();
4229 if( has_ammo && has_mag ) {
4230 ret = c_green;
4231 break;
4232 } else if( has_ammo || has_mag ) {
4233 ret = c_light_red;
4234 break;
4235 }
4236 }
4237 } else if( is_ammo() ) {
4238 // Likewise, ammo is green if you have guns that use it
4239 // ltred if you have the gun but no mags
4240 // Gun with integrated mag counts as both
4241 bool has_gun = p.has_item_with( [this]( const item & i ) {
4242 return i.is_gun() && i.ammo_types().count( ammo_type() );
4243 } );
4244 bool has_mag = p.has_item_with( [this]( const item & i ) {
4245 return ( i.is_gun() && i.magazine_integral() && i.ammo_types().count( ammo_type() ) ) ||
4246 ( i.is_magazine() && i.ammo_types().count( ammo_type() ) );
4247 } );
4248 if( has_gun && has_mag ) {
4249 ret = c_green;
4250 } else if( has_gun || has_mag ) {
4251 ret = c_light_red;
4252 }
4253 } else if( is_magazine() ) {
4254 // Magazines are green if you have guns and ammo for them
4255 // ltred if you have one but not the other
4256 bool has_gun = p.has_item_with( [this]( const item & it ) {
4257 return it.is_gun() && it.magazine_compatible().count( typeId() ) > 0;
4258 } );
4259 bool has_ammo = !character_funcs::find_ammo_items_or_mags( p, *this, false, -1 ).empty();
4260 if( has_gun && has_ammo ) {
4261 ret = c_green;
4262 } else if( has_gun || has_ammo ) {
4263 ret = c_light_red;
4264 }
4265 } else if( is_book() ) {
4266 const islot_book &tmp = *type->book;
4267 // Player doesn't actually interested if NPC has identified book yet.
4268 // So we check identification for human avatar.
4269 if( get_avatar().has_identified( typeId() ) ) {
4270 if( tmp.skill && // Book can improve skill: blue
4272 p.get_skill_level( tmp.skill ) >= tmp.req &&
4273 p.get_skill_level( tmp.skill ) < tmp.level ) {
4274 ret = c_light_blue;
4275 } else if( type->can_use( "MA_MANUAL" ) &&
4276 !p.martial_arts_data->has_martialart( martial_art_learned_from( *type ) ) ) {
4277 ret = c_light_blue;
4278 } else if( tmp.skill && // Book can't improve skill right now, but maybe later: pink
4280 p.get_skill_level( tmp.skill ) < tmp.level ) {
4281 ret = c_pink;
4282 } else if( !p.studied_all_recipes(
4283 *type ) ) { // Book can't improve skill anymore, but has more recipes: yellow
4284 ret = c_yellow;
4285 }
4286 } else if( tmp.skill || type->can_use( "MA_MANUAL" ) ) {
4287 // Book can teach you something and hasn't been identified yet
4288 ret = c_red;
4289 } else {
4290 // "just for fun" book that they haven't read yet
4291 ret = c_magenta;
4292 }
4293 }
4294 return ret;
4295}
morale_type allergy_type(const item &food) const
Returns allergy type or MORALE_NULL if not allergic for this character.
pimpl< character_martial_arts > martial_arts_data
Definition: character.h:1584
ret_val< edible_rating > will_eat(const item &food, bool interactive=false) const
Same as can_eat, but takes consequences into account.
bool has_bionic(const bionic_id &b) const
Returns true if the player has the entered bionic id.
Definition: character.cpp:1809
std::map< bodypart_id, int > bionic_installation_issues(const bionic_id &bioid) const
Definition: bionics.cpp:2572
bool has_trait(const trait_id &b) const override
Returns true if the player has the entered trait.
Definition: mutation.cpp:101
pimpl< known_magic > magic
Definition: character.h:1480
bool is_favorite
Definition: item.h:2243
std::set< itype_id > magazine_compatible(bool conversion=true) const
Get compatible magazines (if any) for this item.
Definition: item.cpp:7701
bool has_fault(const fault_id &fault) const
Does this item have the specified fault.
Definition: item.cpp:5293
bool is_filthy() const
Marks the item as filthy, so characters with squeamish trait can't wear it.
Definition: item.cpp:9981
bool is_food_container() const
Definition: item.cpp:6608
const use_function * get_use(const std::string &use_name) const
Returns the pointer to use_function with name use_name assigned to the type of this item or any of it...
Definition: item.cpp:7948
bool can_revive() const
Whether this is a corpse that can be revived.
Definition: item.cpp:5957
bool has_own_flag(const std::string &flag) const
Checks whether item itself has given flag (doesn't check item type or gunmods).
Definition: item.cpp:5298
Learn a spell.
Definition: iuse_actor.h:799
std::vector< std::string > spells
Definition: iuse_actor.h:802
bool studied_all_recipes(const itype &book) const
Definition: player.cpp:262
The class represents a composite return value of an arbitrary function (result).
Definition: ret_val.h:21
T value() const
Definition: ret_val.h:74
bool has_item_with(const std::function< bool(const item &)> &filter) const
Returns true if any item (including those within a container) matches the filter.
Definition: visitable.cpp:104
#define c_white
Definition: color.h:18
#define c_light_gray
Definition: color.h:19
#define c_green
Definition: color.h:22
#define c_light_green
Definition: color.h:28
#define c_magenta
Definition: color.h:25
#define c_brown
Definition: color.h:26
#define c_dark_gray
Definition: color.h:20
#define c_pink
Definition: color.h:31
#define c_yellow
Definition: color.h:32
#define c_cyan
Definition: color.h:24
#define c_light_red
Definition: color.h:27
#define c_red
Definition: color.h:21
static const std::string flag_WET("WET")
static const trait_id trait_WOOLALLERGY("WOOLALLERGY")
static const fault_id fault_bionic_nonsterile("fault_bionic_nonsterile")
static const std::string flag_LEAK_DAM("LEAK_DAM")
static const std::string flag_LITCIG("LITCIG")
static const std::string flag_RADIOACTIVE("RADIOACTIVE")
std::vector< const item * > get_ammo_items(const Character &who, const ammotype &at)
Returns character's items that are ammo and have the matching ammo type.
std::vector< item_location > find_ammo_items_or_mags(const Character &who, const item &obj, bool empty, int radius)
Searches for ammo or magazines that can be used to reload given item.
Definition: iuse.h:25
string_id< material_type > material_id
Definition: type_id.h:95

References active, allergy, Character::allergy_type(), allergy_weak, ammo_type(), ammo_types(), itype::bionic, Character::bionic_installation_issues(), bloated, itype::book, c_brown, c_cyan, c_dark_gray, c_green, c_light_blue, c_light_gray, c_light_green, c_light_red, c_magenta, c_pink, c_red, c_white, c_yellow, can_revive(), SkillLevel::can_train(), itype::can_use(), cannibalism, itype::container, damage(), edible, fault_bionic_nonsterile, character_funcs::find_ammo_items_or_mags(), flag_LEAK_DAM(), flag_LITCIG(), flag_RADIOACTIVE(), flag_WET(), character_funcs::get_ammo_items(), get_avatar(), get_food(), Character::get_skill_level(), Character::get_skill_level_object(), get_use(), Character::has_bionic(), has_fault(), has_flag(), visitable< T >::has_item_with(), has_own_flag(), Character::has_trait(), inedible, inedible_mutation, is_ammo(), is_armor(), is_bionic(), is_book(), is_corpse(), is_favorite, is_filthy(), is_food(), is_food_container(), is_gun(), is_magazine(), islot_book::level, made_of(), magazine_compatible(), magazine_integral(), Character::magic, martial_art_learned_from(), Character::martial_arts_data, nausea, no_tool, islot_book::req, cata::hash64_detail::ret, rotten, islot_book::skill, learn_spell_actor::spells, player::studied_all_recipes(), too_full, trait_WOOLALLERGY, type, typeId(), ret_val< T >::value(), and Character::will_eat().

◆ combat_info()

void item::combat_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3398 of file item.cpp.

3400{
3401 const std::string space = " ";
3402
3403 int dmg_bash = damage_melee( DT_BASH );
3404 int dmg_cut = damage_melee( DT_CUT );
3405 int dmg_stab = damage_melee( DT_STAB );
3406 if( parts->test( iteminfo_parts::BASE_DAMAGE ) ) {
3408 std::string sep;
3409 if( dmg_bash || dmg_cut || dmg_stab ) {
3410 info.push_back( iteminfo( "BASE", _( "<bold>Melee damage</bold>: " ), "", iteminfo::no_newline ) );
3411 }
3412 if( dmg_bash ) {
3413 info.push_back( iteminfo( "BASE", _( "Bash: " ), "", iteminfo::no_newline, dmg_bash ) );
3414 sep = space;
3415 }
3416 if( dmg_cut ) {
3417 info.push_back( iteminfo( "BASE", sep + _( "Cut: " ), "", iteminfo::no_newline, dmg_cut ) );
3418 sep = space;
3419 }
3420 if( dmg_stab ) {
3421 info.push_back( iteminfo( "BASE", sep + _( "Pierce: " ), "", iteminfo::no_newline, dmg_stab ) );
3422 }
3423 }
3424
3425 if( dmg_bash || dmg_cut || dmg_stab ) {
3426 if( parts->test( iteminfo_parts::BASE_TOHIT ) ) {
3427 info.push_back( iteminfo( "BASE", space + _( "To-hit bonus: " ), "",
3429 }
3430
3431 if( parts->test( iteminfo_parts::BASE_MOVES ) ) {
3432 info.push_back( iteminfo( "BASE", _( "Moves per attack: " ), "",
3434 info.emplace_back( "BASE", _( "Typical damage per second:" ), "" );
3435 const std::map<std::string, double> &dps_data = dps( true, false );
3436 std::string sep;
3437 for( const std::pair<const std::string, double> &dps_entry : dps_data ) {
3438 info.emplace_back( "BASE", sep + dps_entry.first + ": ", "",
3440 dps_entry.second );
3441 sep = space;
3442 }
3443 info.emplace_back( "BASE", "" );
3444 }
3445 }
3446
3448 std::set<matec_id> all_techniques = type->techniques;
3449 all_techniques.insert( techniques.begin(), techniques.end() );
3450
3451 if( !all_techniques.empty() ) {
3452 const std::vector<matec_id> all_tec_sorted = sorted_lex( all_techniques );
3454 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Techniques when wielded</bold>: " ) +
3455 enumerate_as_string( all_tec_sorted.begin(), all_tec_sorted.end(), []( const matec_id & tid ) {
3456 return string_format( "<stat>%s</stat>: <info>%s</info>", _( tid.obj().name ),
3457 _( tid.obj().description ) );
3458 } ) ) );
3459 }
3460 }
3461
3462 avatar &you = get_avatar();
3463 // display which martial arts styles character can use with this weapon
3465 const std::string valid_styles = you.martial_arts_data->enumerate_known_styles( typeId() );
3466 if( !valid_styles.empty() ) {
3468 info.push_back( iteminfo( "DESCRIPTION",
3469 _( "You know how to use this with these martial arts "
3470 "styles: " ) + valid_styles ) );
3471 }
3472 }
3473
3474 if( !is_gunmod() && has_flag( flag_REACH_ATTACK ) &&
3477 if( has_flag( flag_REACH3 ) ) {
3478 info.push_back( iteminfo( "DESCRIPTION",
3479 _( "* This item can be used to make <stat>long reach "
3480 "attacks</stat>." ) ) );
3481 } else {
3482 info.push_back( iteminfo( "DESCRIPTION",
3483 _( "* This item can be used to make <stat>reach "
3484 "attacks</stat>." ) ) );
3485 }
3486 }
3487
3488 if( ( dmg_bash || dmg_cut || dmg_stab || type->m_to_hit > 0 ) || debug_mode ) {
3489 damage_instance non_crit;
3490 you.roll_all_damage( false, non_crit, true, *this );
3491 damage_instance crit;
3492 you.roll_all_damage( true, crit, true, *this );
3493 int attack_cost = you.attack_cost( *this );
3496 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Average melee damage</bold>:" ) ) );
3497 }
3498 // Chance of critical hit
3500 info.push_back( iteminfo( "DESCRIPTION",
3501 string_format( _( "Critical hit chance <neutral>%d%% - %d%%</neutral>" ),
3502 static_cast<int>( you.crit_chance( 0, 100, *this ) *
3503 100 ),
3504 static_cast<int>( you.crit_chance( 100, 0, *this ) *
3505 100 ) ) ) );
3506 }
3507 // Bash damage
3509 // NOTE: Using "BASE" instead of "DESCRIPTION", so numerical formatting will work
3510 // (output.cpp:format_item_info does not interpolate <num> for DESCRIPTION info)
3511 info.push_back( iteminfo( "BASE", _( "Bashing: " ), "<num>", iteminfo::no_newline,
3512 non_crit.type_damage( DT_BASH ) ) );
3513 info.push_back( iteminfo( "BASE", space + _( "Critical bash: " ), "<num>", iteminfo::no_flags,
3514 crit.type_damage( DT_BASH ) ) );
3515 }
3516 // Cut damage
3517 if( ( non_crit.type_damage( DT_CUT ) > 0.0f || crit.type_damage( DT_CUT ) > 0.0f )
3519
3520 info.push_back( iteminfo( "BASE", _( "Cutting: " ), "<num>", iteminfo::no_newline,
3521 non_crit.type_damage( DT_CUT ) ) );
3522 info.push_back( iteminfo( "BASE", space + _( "Critical cut: " ), "<num>", iteminfo::no_flags,
3523 crit.type_damage( DT_CUT ) ) );
3524 }
3525 // Pierce/stab damage
3526 if( ( non_crit.type_damage( DT_STAB ) > 0.0f || crit.type_damage( DT_STAB ) > 0.0f )
3528
3529 info.push_back( iteminfo( "BASE", _( "Piercing: " ), "<num>", iteminfo::no_newline,
3530 non_crit.type_damage( DT_STAB ) ) );
3531 info.push_back( iteminfo( "BASE", space + _( "Critical pierce: " ), "<num>", iteminfo::no_flags,
3532 crit.type_damage( DT_STAB ) ) );
3533 }
3534 // Moves
3536 info.push_back( iteminfo( "BASE", _( "Moves per attack: " ), "<num>",
3538 }
3540 }
3541}
bool debug_mode
Extended debugging mode, can be toggled during game.
int attack_cost(const item &weap) const
Returns cost (in moves) of attacking with given item (no modifiers, like stuck)
Definition: melee.cpp:2251
double crit_chance(float roll_hit, float target_dodge, const item &weap) const
Returns the chance to critical given a hit roll and target's dodge roll.
Definition: melee.cpp:768
void roll_all_damage(bool crit, damage_instance &di, bool average, const item &weap) const
Adds all 3 types of physical damage to instance.
Definition: melee.cpp:383
int attack_cost() const
Base number of moves (Creature::moves) that a single melee attack with this items takes.
Definition: item.cpp:5181
@ DT_STAB
Definition: damage.h:27
@ DT_BASH
Definition: damage.h:24
@ DT_CUT
Definition: damage.h:25
static const std::string flag_REACH3("REACH3")
static const std::string flag_REACH_ATTACK("REACH_ATTACK")
@ DESCRIPTION_MELEEDMG_PIERCE
@ DESCRIPTION_GUNMOD_ADDREACHATTACK
@ DESCRIPTION_MELEEDMG_MOVES
@ DESCRIPTION_APPLICABLEMARTIALARTS
float type_damage(damage_type dt) const
Definition: damage.cpp:64
int m_to_hit
Definition: itype.h:998
std::set< matec_id > techniques
Definition: itype.h:933

References _, attack_cost(), Character::attack_cost(), BASE_DAMAGE, BASE_MOVES, BASE_TOHIT, Character::crit_chance(), damage_melee(), debug_mode, DESCRIPTION_APPLICABLEMARTIALARTS, DESCRIPTION_GUNMOD_ADDREACHATTACK, DESCRIPTION_MELEEDMG, DESCRIPTION_MELEEDMG_BASH, DESCRIPTION_MELEEDMG_CRIT, DESCRIPTION_MELEEDMG_CUT, DESCRIPTION_MELEEDMG_MOVES, DESCRIPTION_MELEEDMG_PIERCE, DESCRIPTION_TECHNIQUES, dps(), DT_BASH, DT_CUT, DT_STAB, enumerate_as_string(), flag_REACH3(), flag_REACH_ATTACK(), get_avatar(), has_flag(), info(), insert_separation_line(), iteminfo::is_decimal, is_gunmod(), iteminfo::lower_is_better, itype::m_to_hit, Character::martial_arts_data, iteminfo::no_flags, iteminfo::no_newline, Character::roll_all_damage(), iteminfo::show_plus, sorted_lex(), sign::space, string_format(), techniques, itype::techniques, iteminfo_query::test(), type, damage_instance::type_damage(), and typeId().

Referenced by info().

◆ common_ammo_default()

itype_id item::common_ammo_default ( bool  conversion = true) const

Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
itype_id of default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists

Definition at line 7617 of file item.cpp.

7618{
7619 if( !ammo_types( conversion ).empty() ) {
7620 for( const ammotype &at : ammo_types( conversion ) ) {
7621 const item *mag = magazine_current();
7622 if( mag && mag->type->magazine->type.count( at ) ) {
7623 itype_id res = at->default_ammotype();
7624 if( !res.is_empty() ) {
7625 return res;
7626 }
7627 }
7628 }
7629 }
7630 return itype_id::NULL_ID();
7631}

References ammo_types(), string_id< T >::is_empty(), itype::magazine, magazine_current(), string_id< itype >::NULL_ID(), and type.

Referenced by gun_info().

◆ component_info()

void item::component_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3129 of file item.cpp.

3131{
3133 return;
3134 }
3135 if( is_craft() ) {
3136 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Using: %s" ),
3137 _( components_to_string() ) ) ) );
3138 // Ugly hack warning! Corpses have CBMs as their components
3139 } else if( !is_corpse() ) {
3140 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Made from: %s" ),
3141 _( components_to_string() ) ) ) );
3142 } else if( get_var( "bionics_scanned_by", -1 ) == get_avatar().getID().get_value() ) {
3143 // TODO: Extract into a more proper place (function in namespace)
3144 std::string bionics_string = enumerate_as_string( components.begin(), components.end(),
3145 []( const item & entry ) -> std::string {
3146 return entry.is_bionic() ? entry.display_name() : "";
3148 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Contains: %s" ),
3149 bionics_string ) ) );
3150 }
3151}
std::string components_to_string() const
List of all components in printable form, empty if this item has no components.
Definition: item.cpp:8896
@ DESCRIPTION_COMPONENTS_MADEFROM

References _, components, components_to_string(), DESCRIPTION_COMPONENTS_MADEFROM, enumerate_as_string(), get_avatar(), get_var(), info(), is_corpse(), is_craft(), none, string_format(), and iteminfo_query::test().

Referenced by info().

◆ components_to_string()

std::string item::components_to_string ( ) const

List of all components in printable form, empty if this item has no components.

Definition at line 8896 of file item.cpp.

8897{
8898 using t_count_map = std::map<std::string, int>;
8899 t_count_map counts;
8900 for( const item &elem : components ) {
8901 if( !elem.has_flag( flag_BYPRODUCT ) ) {
8902 const std::string name = elem.display_name();
8903 counts[name]++;
8904 }
8905 }
8906 return enumerate_as_string( counts.begin(), counts.end(),
8907 []( const std::pair<std::string, int> &entry ) -> std::string {
8908 if( entry.second != 1 )
8909 {
8910 return string_format( pgettext( "components count", "%d x %s" ), entry.second, entry.first );
8911 } else
8912 {
8913 return entry.first;
8914 }
8916}
static const std::string flag_BYPRODUCT("BYPRODUCT")

References components, enumerate_as_string(), flag_BYPRODUCT(), and om_direction::name().

Referenced by component_info().

◆ conductive()

bool item::conductive ( ) const

Whether the items is conductive.

Definition at line 6478 of file item.cpp.

6479{
6480 if( is_null() ) {
6481 return false;
6482 }
6483
6484 if( has_flag( flag_CONDUCTIVE ) ) {
6485 return true;
6486 }
6487
6488 if( has_flag( flag_NONCONDUCTIVE ) ) {
6489 return false;
6490 }
6491
6492 // If any material has electricity resistance equal to or lower than flesh (1) we are conductive.
6493 const std::vector<const material_type *> &mats = made_of_types();
6494 return std::any_of( mats.begin(), mats.end(), []( const material_type * mt ) {
6495 return mt->elec_resist() <= 1;
6496 } );
6497}
static const std::string flag_CONDUCTIVE("CONDUCTIVE")
static const std::string flag_NONCONDUCTIVE("NONCONDUCTIVE")

References flag_CONDUCTIVE(), flag_NONCONDUCTIVE(), has_flag(), is_null(), and made_of_types().

Referenced by Character::block_hit(), final_info(), and mdefense::zapback().

◆ contain_monster()

int item::contain_monster ( const tripoint target)

Definition at line 9257 of file iuse.cpp.

9258{
9259 const monster *const mon_ptr = g->critter_at<monster>( target );
9260 if( !mon_ptr ) {
9261 return 0;
9262 }
9263 const monster &f = *mon_ptr;
9264
9265 set_var( "contained_json", ::serialize( f ) );
9266 set_var( "contained_name", f.type->nname() );
9267 set_var( "name", string_format( _( "%s holding %s" ), type->nname( 1 ),
9268 f.type->nname() ) );
9269 // Need to add the weight of the empty container because item::weight uses the "weight" variable directly.
9270 set_var( "weight", to_milligram( type->weight + f.get_weight() ) );
9271 g->remove_zombie( f );
9272 return 0;
9273}
void serialize(JsonOut &json) const
const mtype * type
Definition: monster.h:478
units::mass get_weight() const override
Definition: monster.cpp:2734
constexpr value_type to_milligram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:62
units::mass weight
Weight of item ( or each stack member )
Definition: itype.h:965
std::string nname(unsigned int quantity) const
Definition: itype.cpp:78
std::string nname(unsigned int quantity=1) const
Definition: mtype.cpp:65

References _, g, monster::get_weight(), itype::nname(), mtype::nname(), serialize(), set_var(), string_format(), units::to_milligram(), type, monster::type, and itype::weight.

Referenced by iuse::capture_monster_act().

◆ container_info()

void item::container_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3034 of file item.cpp.

3036{
3037 if( !is_container() || !parts->test( iteminfo_parts::CONTAINER_DETAILS ) ) {
3038 return;
3039 }
3040
3042 const islot_container &c = *type->container;
3043
3044 std::string container_str = _( "This container " );
3045
3046 if( c.seals ) {
3047 container_str += _( "can be <info>resealed</info>, " );
3048 }
3049 if( c.watertight ) {
3050 container_str += _( "is <info>watertight</info>, " );
3051 }
3052 if( c.preserves ) {
3053 container_str += _( "<good>prevents spoiling</good>, " );
3054 }
3055
3056 container_str += string_format( _( "can store <info>%s %s</info>." ),
3057 format_volume( c.contains ), volume_units_long() );
3058
3059 info.push_back( iteminfo( "CONTAINER", container_str ) );
3060}
bool is_container() const
Whether this is container.
Definition: item.cpp:6719
std::string format_volume(const units::volume &volume)
Convert, round up and format a volume.
Definition: output.cpp:2020
const char * volume_units_long()
Create a units label for a volume value.

References _, c, itype::container, CONTAINER_DETAILS, format_volume(), info(), insert_separation_line(), is_container(), string_format(), iteminfo_query::test(), type, and volume_units_long().

Referenced by info().

◆ contents_info()

void item::contents_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3543 of file item.cpp.

3545{
3547 return;
3548 }
3549 const std::string space = " ";
3550
3551 for( const item *mod : is_gun() ? gunmods() : toolmods() ) {
3552 std::string mod_str;
3553 if( mod->type->gunmod ) {
3554 if( mod->is_irremovable() ) {
3555 mod_str = _( "Integrated mod: " );
3556 } else {
3557 mod_str = _( "Mod: " );
3558 }
3559 mod_str += string_format( "<bold>%s</bold> (%s) ", mod->tname(),
3560 mod->type->gunmod->location.name() );
3561 }
3563 info.emplace_back( "DESCRIPTION", mod_str );
3564 info.emplace_back( "DESCRIPTION", mod->type->description.translated() );
3565 }
3566 bool contents_header = false;
3567 for( const item *contents_item : contents.all_items_top() ) {
3568 if( !contents_item->type->mod ) {
3569 if( !contents_header ) {
3571 info.emplace_back( "DESCRIPTION", _( "<bold>Contents of this item</bold>:" ) );
3572 contents_header = true;
3573 } else {
3574 // Separate items with a blank line
3575 info.emplace_back( "DESCRIPTION", space );
3576 }
3577
3578 const translation &description = contents_item->type->description;
3579
3580 if( contents_item->made_of( LIQUID ) ) {
3581 units::volume contents_volume = contents_item->volume() * batch;
3582 int converted_volume_scale = 0;
3583 const double converted_volume =
3584 round_up( convert_volume( contents_volume.value(),
3585 &converted_volume_scale ), 2 );
3586 info.emplace_back( "DESCRIPTION", contents_item->display_name() );
3588 if( display_mod_source ) {
3589 info.emplace_back( "DESCRIPTION", string_format( _( "<stat>Origin: %s</stat>" ),
3590 enumerate_as_string( contents_item->type->src.begin(),
3591 contents_item->type->src.end(), []( const std::pair<itype_id, mod_id> &content_source ) {
3592 return string_format( "'%s'", content_source.second->name() );
3594 }
3595 if( display_object_ids ) {
3596 info.emplace_back( "DESCRIPTION", colorize(
3597 string_format( "[%s]", contents_item->type->get_id() ),
3598 c_light_blue ) );
3599 }
3600 if( converted_volume_scale != 0 ) {
3602 }
3603 info.emplace_back( "CONTAINER", description + space,
3604 string_format( "<num> %s", volume_units_abbr() ), f,
3605 converted_volume );
3606 } else {
3607 info.emplace_back( "DESCRIPTION", contents_item->display_name() );
3608 if( display_mod_source ) {
3609 info.emplace_back( "DESCRIPTION", string_format( _( "<stat>Origin: %s</stat>" ),
3610 enumerate_as_string( contents_item->type->src.begin(),
3611 contents_item->type->src.end(), []( const std::pair<itype_id, mod_id> &content_source ) {
3612 return string_format( "'%s'", content_source.second->name() );
3614 }
3615 if( display_object_ids ) {
3616 info.emplace_back( "DESCRIPTION", colorize(
3617 string_format( "[%s]", contents_item->type->get_id() ),
3618 c_light_blue ) );
3619 }
3620 info.emplace_back( "DESCRIPTION", description.translated() );
3621 }
3622 }
3623 }
3624}
Class for storing translation context and raw string for deferred translation.
Definition: translations.h:152
constexpr const value_type & value() const
Access the raw dimensionless value.
Definition: units_def.h:44

References _, item_contents::all_items_top(), arrow, c_light_blue, colorize(), contents, convert_volume(), DESCRIPTION_CONTENTS, display_mod_source, display_object_ids, item_contents::empty(), enumerate_as_string(), gunmods(), info(), insert_separation_line(), iteminfo::is_decimal, is_gun(), LIQUID, iteminfo::no_newline, round_up(), sign::space, string_format(), iteminfo_query::test(), toolmods(), translation::translated(), units::quantity< V, U >::value(), and volume_units_abbr().

Referenced by info().

◆ contents_made_of()

bool item::contents_made_of ( phase_id  phase) const

If contents nonempty, return true if item phase is same, else false.

Definition at line 6465 of file item.cpp.

6466{
6467 return !contents.empty() && contents.front().made_of( phase );
6468}

References contents, item_contents::empty(), item_contents::front(), and made_of().

Referenced by character_funcs::find_ammo_helper().

◆ contextualize_skill()

skill_id item::contextualize_skill ( const skill_id id) const

Puts the skill in context of the item.

Definition at line 9966 of file item.cpp.

9967{
9968 if( id->is_contextual_skill() ) {
9969 if( id == skill_weapon ) {
9970 if( is_gun() ) {
9971 return gun_skill();
9972 } else if( is_melee() ) {
9973 return melee_skill();
9974 }
9975 }
9976 }
9977
9978 return id;
9979}
skill_id gun_skill() const
The skill used to operate the gun.
Definition: item.cpp:7187
skill_id melee_skill() const
The most relevant skill used with this melee weapon.
Definition: item.cpp:7208
bool is_melee() const
Is this item an effective melee weapon for any damage type?
Definition: item.cpp:6667
static const skill_id skill_weapon("weapon")
const std::string id
Definition: basecamp.h:87

References gun_skill(), base_camps::id, is_gun(), is_melee(), melee_skill(), and skill_weapon.

Referenced by Character::enumerate_unmet_requirements(), and SkillLevelMap::get_skill_level().

◆ convert()

◆ corpse_volume()

units::volume item::corpse_volume ( const mtype corpse) const

Volume check for corpses, helper for base_volume().

Definition at line 5054 of file item.cpp.

5055{
5057 if( has_flag( flag_QUARTERED ) ) {
5058 corpse_volume /= 4;
5059 }
5061 corpse_volume *= 0.75;
5062 }
5063 if( has_flag( flag_GIBBED ) ) {
5064 corpse_volume *= 0.85;
5065 }
5066 if( has_flag( flag_SKINNED ) ) {
5067 corpse_volume *= 0.85;
5068 }
5069 if( corpse_volume > 0_ml ) {
5070 return corpse_volume;
5071 }
5072 debugmsg( "invalid monster volume for corpse" );
5073 return 0_ml;
5074}
static const std::string flag_GIBBED("GIBBED")
units::volume volume
Definition: mtype.h:263

References corpse, corpse_volume(), debugmsg, flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_GIBBED(), flag_QUARTERED(), flag_SKINNED(), has_flag(), and mtype::volume.

Referenced by base_volume(), corpse_volume(), and volume().

◆ count()

◆ count_by_charges() [1/2]

bool item::count_by_charges ( ) const

Definition at line 6005 of file item.cpp.

6006{
6007 return type->count_by_charges();
6008}

References itype::count_by_charges(), and type.

Referenced by activity_on_turn_wear(), vehicle::add_charges(), vehicle::add_item(), map::add_item_or_charges(), item_stack::amount_can_fit(), base_volume(), basic_info(), burn(), Character::can_eat(), repair_item_actor::can_repair_target(), charges_of_internal(), charges_per_volume(), craft_command::check_item_components_missing(), complete_craft(), crafting::complete_disassemble(), player::consume_items(), count(), craft_has_charges(), recipe::create_byproducts(), recipe::create_results(), display_name(), display_stacked_with(), move_items_activity_actor::do_turn(), throw_activity_actor::do_turn(), mattack::eat_food(), farm_action(), Character::feed_furnace_with(), fetch_activity(), talk_function::field_harvest(), talk_function::field_plant(), iuse_transform::finalize(), emit_actor::finalize(), for_each_item_in_both(), Character::get_acquirable_energy(), recipe::get_consistency_error(), requirement_data::get_folded_list(), iexamine::get_harvest_items(), monexamine::give_items_to(), repair_item_actor::handle_components(), item_comp::has(), talk_function::individual_mission(), io(), repair_inventory_preset::is_shown(), merge_charges(), to_cbc_migration::migration_required(), mod_charges(), mod_damage(), Item_modifier::modify(), advanced_inventory::move_all_items(), move_item(), npc_throw(), pickup::obtain_and_tokenize_items(), pick_one_up(), pickup::pick_up(), activity_handlers::plant_seed_finish(), price(), advanced_inventory::query_charges(), vehicle::reload_seeds(), player::select_item_component(), talk_effect_fun_t::set_u_buy_item(), talk_effect_fun_t::set_u_sell_item(), simulate_burn(), spell_effect::spawn_ethereal_item(), split(), stacks_with(), Character::throw_range(), ranged::throwing_dispersion(), npc_trading::trade(), try_consume(), units_remaining(), units_sufficient(), inventory::update_quality_cache(), use_charges(), volume(), weight(), Character::weight_carried_reduced_by(), and debug_menu::wishitem().

◆ count_by_charges() [2/2]

bool item::count_by_charges ( const itype_id id)
static

Whether the item is counted by charges, this is a static wrapper around count_by_charges, that does not need an items instance.

Definition at line 9927 of file item.cpp.

9928{
9929 return id->count_by_charges();
9930}

◆ covers() [1/2]

◆ covers() [2/2]

bool item::covers ( const bodypart_id bp) const

Definition at line 748 of file item.cpp.

749{
750 return get_covered_body_parts().test( bp->token );
751}
bool test(const body_part &bp) const
Definition: bodypart.h:239

References get_covered_body_parts(), and body_part_set::test().

◆ craft_has_charges()

bool item::craft_has_charges ( )

Definition at line 6015 of file item.cpp.

6016{
6017 if( count_by_charges() ) {
6018 return true;
6019 } else if( ammo_types().empty() ) {
6020 return true;
6021 }
6022
6023 return false;
6024}

References ammo_types(), and count_by_charges().

Referenced by crafting::complete_disassemble(), and recipe::create_byproducts().

◆ cut_resist()

int item::cut_resist ( bool  to_self = false) const

Definition at line 6059 of file item.cpp.

6060{
6061 if( is_null() ) {
6062 return 0;
6063 }
6064
6065 const int base_thickness = get_thickness();
6066 float resist = 0;
6068 int eff_thickness = 1;
6069
6070 // base resistance
6071 // Don't give reinforced items +armor, just more resistance to ripping
6072 const int dmg = damage_level( 4 );
6073 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6074 eff_thickness = std::max( 1, base_thickness - eff_damage );
6075
6076 const std::vector<const material_type *> mat_types = made_of_types();
6077 if( !mat_types.empty() ) {
6078 for( const material_type *mat : mat_types ) {
6079 resist += mat->cut_resist();
6080 }
6081 // Average based on number of materials.
6082 resist /= mat_types.size();
6083 }
6084
6085 return std::lround( ( resist * eff_thickness ) + mod );
6086}
@ clothing_mod_type_cut
Definition: clothing_mod.h:20

References clothing_mod_type_cut, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), stab_resist(), and sew_advanced_actor::use().

◆ damage()

◆ damage_color()

nc_color item::damage_color ( ) const

Provide color for UI display dependent upon current item damage level.

Definition at line 6263 of file item.cpp.

6264{
6265 // TODO: unify with veh_interact::countDurability
6266 switch( damage_level( 4 ) ) {
6267 default:
6268 // reinforced
6269 if( damage() <= min_damage() ) {
6270 // fully reinforced
6271 return c_green;
6272 } else {
6273 return c_light_green;
6274 }
6275 case 0:
6276 return c_light_green;
6277 case 1:
6278 return c_yellow;
6279 case 2:
6280 return c_magenta;
6281 case 3:
6282 return c_light_red;
6283 case 4:
6284 if( damage() >= max_damage() ) {
6285 return c_dark_gray;
6286 } else {
6287 return c_red;
6288 }
6289 }
6290}
int min_damage() const
Minimum amount of damage to an item (state of maximum repair)
Definition: item.cpp:6211

References c_dark_gray, c_green, c_light_green, c_light_red, c_magenta, c_red, c_yellow, damage(), damage_level(), max_damage(), and min_damage().

Referenced by durability_indicator(), vehicle_part::name(), and veh_utils::repair_part().

◆ damage_level()

int item::damage_level ( int  max) const

Scale item damage to the given number of levels.

This function is here mostly for back-compatibility. It should not be used when doing continuous math with the damage value: use damage() instead.

For example, for max = 4, min_damage = -1000, max_damage = 4000 damage level -1000 ~ -1 -1 0 0 1 ~ 1333 1 1334 ~ 2666 2 2667 ~ 3999 3 4000 4

Parameters
maxMaximum number of levels

Definition at line 701 of file item.cpp.

702{
703 if( damage_ == 0 || max <= 0 ) {
704 return 0;
705 } else if( max_damage() <= 1 ) {
706 return damage_ > 0 ? max : damage_;
707 } else if( damage_ < 0 ) {
708 return -( ( max - 1 ) * ( -damage_ - 1 ) / ( max_damage() - 1 ) + 1 );
709 } else {
710 return ( max - 1 ) * ( damage_ - 1 ) / ( max_damage() - 1 ) + 1;
711 }
712}

References damage_, and max_damage().

Referenced by Character::armor_absorb(), bash_resist(), bullet_resist(), activity_handlers::butcher_finish(), butchery_drops_harvest(), iuse::chainsaw_off(), crafting::complete_disassemble(), iuse::cs_lajatang_off(), cut_resist(), salvage_actor::cut_up(), damage_color(), vehicle_part::damage_level(), damage_melee(), damage_symbol(), veh_interact::do_repair(), durability_indicator(), gun_damage(), gun_dispersion(), avatar_funcs::gunmod_installation_odds(), monster::init_from_item(), vehicle_part::properties_to_item(), ready_to_revive(), repair_item_actor::repair_chance(), game::save_cyborg(), iuse::trimmer_off(), and fireweapon_off_actor::use().

◆ damage_melee()

int item::damage_melee ( damage_type  dt) const

Damage of given type caused when this item is used as melee weapon.

Definition at line 5188 of file item.cpp.

5189{
5190 assert( dt >= DT_NULL && dt < NUM_DT );
5191 if( is_null() ) {
5192 return 0;
5193 }
5194
5195 // effectiveness is reduced by 10% per damage level
5196 int res = type->melee[ dt ];
5197 res -= res * std::max( damage_level( 4 ), 0 ) * 0.1;
5198
5199 // apply type specific flags
5200 switch( dt ) {
5201 case DT_BASH:
5203 res *= 0.5;
5204 }
5205 break;
5206
5207 case DT_CUT:
5208 case DT_STAB:
5209 if( has_flag( flag_DIAMOND ) ) {
5210 res *= 1.3;
5211 }
5212 break;
5213
5214 default:
5215 break;
5216 }
5217
5218 // consider any melee gunmods
5219 if( is_gun() ) {
5220 const std::vector<const item *> &mods = gunmods();
5221 return std::accumulate( mods.begin(), mods.end(), res, [dt]( int last_max, const item * it ) {
5222 return it->has_flag( flag_MELEE_GUNMOD ) ? std::max( last_max, it->damage_melee( dt ) ) : last_max;
5223 } );
5224
5225 }
5226
5227 switch( dt ) {
5228 case DT_BASH:
5230 break;
5231 case DT_CUT:
5233 break;
5234 case DT_STAB:
5236 break;
5237 default:
5238 break;
5239 }
5240
5241 return std::max( res, 0 );
5242}
static const std::string flag_DIAMOND("DIAMOND")
static const std::string flag_REDUCED_BASHING("REDUCED_BASHING")
std::array< int, NUM_DT > melee
Damage output in melee for zero or more damage types.
Definition: itype.h:994

References bonus_from_enchantments_wielded(), damage_level(), DT_BASH, DT_CUT, DT_NULL, DT_STAB, flag_DIAMOND(), flag_REDUCED_BASHING(), gunmods(), has_flag(), is_gun(), is_null(), enchant_vals::ITEM_DAMAGE_BASH, enchant_vals::ITEM_DAMAGE_CUT, enchant_vals::ITEM_DAMAGE_STAB, itype::melee, NUM_DT, and type.

Referenced by base_damage_melee(), combat_info(), weapon_inventory_preset::deals_melee_damage(), character_effects::intimidation(), is_melee(), ma_requirements::is_valid_weapon(), melee_skill(), Character::melee_special_effects(), melee_train(), Character::power_rating(), activity_handlers::pulp_do_turn(), Character::reach_attack(), Character::roll_bash_damage(), Character::roll_cut_damage(), Character::roll_stab_damage(), smash(), and npc::smash_ability().

◆ damage_resist()

int item::damage_resist ( damage_type  dt,
bool  to_self = false 
) const

Resistance provided by this item against damage type given by an enum.

Definition at line 6371 of file item.cpp.

6372{
6373 switch( dt ) {
6374 case DT_NULL:
6375 case NUM_DT:
6376 return 0;
6377 case DT_TRUE:
6378 case DT_BIOLOGICAL:
6379 case DT_ELECTRIC:
6380 case DT_COLD:
6381 // Currently hardcoded:
6382 // Items can never be damaged by those types
6383 // But they provide 0 protection from them
6384 return to_self ? INT_MAX : 0;
6385 case DT_BASH:
6386 return bash_resist( to_self );
6387 case DT_CUT:
6388 return cut_resist( to_self );
6389 case DT_ACID:
6390 return acid_resist( to_self );
6391 case DT_STAB:
6392 return stab_resist( to_self );
6393 case DT_HEAT:
6394 return fire_resist( to_self );
6395 case DT_BULLET:
6396 return bullet_resist( to_self );
6397 default:
6398 debugmsg( "Invalid damage type: %d", dt );
6399 }
6400
6401 return 0;
6402}
int stab_resist(bool to_self=false) const
Definition: item.cpp:6092
@ DT_COLD
Definition: damage.h:29
@ DT_ELECTRIC
Definition: damage.h:30
@ DT_TRUE
Definition: damage.h:22
@ DT_ACID
Definition: damage.h:26
@ DT_BULLET
Definition: damage.h:31
@ DT_BIOLOGICAL
Definition: damage.h:23
@ DT_HEAT
Definition: damage.h:28

References acid_resist(), bash_resist(), bullet_resist(), cut_resist(), debugmsg, DT_ACID, DT_BASH, DT_BIOLOGICAL, DT_BULLET, DT_COLD, DT_CUT, DT_ELECTRIC, DT_HEAT, DT_NULL, DT_STAB, DT_TRUE, fire_resist(), NUM_DT, and stab_resist().

Referenced by Character::armor_absorb(), and resistances::resistances().

◆ damage_symbol()

std::string item::damage_symbol ( ) const

Provide prefix symbol for UI display dependent upon current item damage level.

Definition at line 6292 of file item.cpp.

6293{
6294 switch( damage_level( 4 ) ) {
6295 default:
6296 // reinforced
6297 return _( R"(++)" );
6298 case 0:
6299 return _( R"(||)" );
6300 case 1:
6301 return _( R"(|\)" );
6302 case 2:
6303 return _( R"(|.)" );
6304 case 3:
6305 return _( R"(\.)" );
6306 case 4:
6307 if( damage() >= max_damage() ) {
6308 return _( R"(XX)" );
6309 } else {
6310 return _( R"(..)" );
6311 }
6312
6313 }
6314}

References _, damage(), damage_level(), and max_damage().

Referenced by durability_indicator(), vehicle_part::name(), and veh_utils::repair_part().

◆ deactivate()

item & item::deactivate ( const Character ch = nullptr,
bool  alert = true 
)

Filter converting this instance to the inactive type If the item is either inactive or cannot be deactivated is a no-op.

Parameters
chcharacter currently possessing or acting upon the item (if any)
alertwhether to display any messages
Returns
same instance to allow method chaining

Definition at line 540 of file item.cpp.

541{
542 if( !active ) {
543 return *this; // no-op
544 }
545
546 if( is_tool() && type->tool->revert_to ) {
547 if( ch && alert && !type->tool->revert_msg.empty() ) {
548 ch->add_msg_if_player( m_info, _( type->tool->revert_msg ), tname() );
549 }
550 convert( *type->tool->revert_to );
551 active = false;
552
553 }
554 return *this;
555}
virtual void add_msg_if_player(const std::string &) const
Definition: creature.h:605
item & convert(const itype_id &new_type)
Filter converting this instance to another type preserving all other aspects.
Definition: item.cpp:533
@ m_info
Definition: enums.h:265

References _, active, Creature::add_msg_if_player(), alert, convert(), is_tool(), m_info, tname(), itype::tool, and type.

Referenced by iuse::note_bionics(), process_tool(), and fireweapon_on_actor::use().

◆ deserialize()

void item::deserialize ( JsonIn jsin)

Definition at line 2366 of file savegame_json.cpp.

2367{
2368 const JsonObject data = jsin.get_object();
2369 data.allow_omitted_members();
2370 io::JsonObjectInputArchive archive( data );
2371 io( archive );
2372 // made for fast forwarding time from 0.D to 0.E
2373 if( savegame_loading_version < 27 ) {
2375 }
2376 if( data.has_array( "contents" ) ) {
2377 std::list<item> items;
2378 data.read( "contents", items );
2379 contents = item_contents( items );
2380 } else {
2381 data.read( "contents", contents );
2382 }
2383
2384 // Sealed item migration: items with "unseals_into" set should always have contents
2386 convert( type->container->unseals_into );
2387 }
2388}
JsonObject get_object()
Definition: json.cpp:1432
bool has_array(const std::string &name) const
Definition: json.cpp:483
void allow_omitted_members() const
Definition: json.cpp:151
bool read(const std::string &name, T &t, bool throw_on_error=true) const
Definition: json.h:941
Input archive reading data from a Json object.
Definition: cata_io.h:185
void io(Archive &)
bool is_non_resealable_container() const
Whether removing this item's contents will permanently alter it.
Definition: item.cpp:6729
void legacy_fast_forward_time()
Definition: item.cpp:10015
int savegame_loading_version
Definition: savegame.cpp:64

References JsonObject::allow_omitted_members(), itype::container, contents, convert(), item_contents::empty(), JsonIn::get_object(), JsonObject::has_array(), io(), is_non_resealable_container(), legacy_fast_forward_time(), JsonObject::read(), savegame_loading_version, and type.

Referenced by item::craft_data::deserialize(), inventory::json_load_items(), monster::load(), and release_monster().

◆ destroyed_at_zero_charges()

bool item::destroyed_at_zero_charges ( ) const

Definition at line 6512 of file item.cpp.

6513{
6514 return ( is_ammo() || is_food() );
6515}

References is_ammo(), and is_food().

◆ detonate()

bool item::detonate ( const tripoint p,
std::vector< item > &  drops 
)

Detonates the item and adds remains (if any) to drops.

Returns true if the item actually detonated, potentially destroying other items and invalidating iterators. Should NOT be called on an item on the map, but on a local copy.

Definition at line 8754 of file item.cpp.

8755{
8756 if( type->explosion ) {
8758 return true;
8759 } else if( type->ammo && ( type->ammo->special_cookoff || type->ammo->cookoff ) ) {
8760 int charges_remaining = charges;
8761 const int rounds_exploded = rng( 1, charges_remaining );
8762 // Yank the exploding item off the map for the duration of the explosion
8763 // so it doesn't blow itself up.
8764 const islot_ammo &ammo_type = *type->ammo;
8765
8766 if( ammo_type.special_cookoff ) {
8767 // If it has a special effect just trigger it.
8768 apply_ammo_effects( p, ammo_type.ammo_effects, activated_by.get() );
8769 }
8770 charges_remaining -= rounds_exploded;
8771 if( charges_remaining > 0 ) {
8772 item temp_item = *this;
8773 temp_item.charges = charges_remaining;
8774 drops.push_back( temp_item );
8775 }
8776
8777 return true;
8778 } else if( !contents.empty() && ( !type->magazine || !type->magazine->protects_contents ) ) {
8779 std::vector<item *> removed_items;
8780 bool detonated = false;
8781 for( item *it : contents.all_items_top() ) {
8782 if( it->detonate( p, drops ) ) {
8783 removed_items.push_back( it );
8784 detonated = true;
8785 }
8786 }
8787 for( item *it : removed_items ) {
8788 remove_item( *it );
8789 }
8790 return detonated;
8791 }
8792
8793 return false;
8794}
safe_reference< Character > activated_by
Definition: item.h:2242
void explosion(const tripoint &p, Creature *source, float power, float factor, bool fire, int legacy_casing_mass, float)
Legacy explosion function.
Definition: explosion.cpp:1079
void apply_ammo_effects(const tripoint &p, const std::set< ammo_effect_str_id > &effects, Creature *source)
Definition: projectile.cpp:110
explosion_data explosion
Definition: itype.h:945

References activated_by, item_contents::all_items_top(), itype::ammo, ammo_type(), apply_ammo_effects(), charges, contents, item_contents::empty(), explosion_handler::explosion(), itype::explosion, itype::magazine, visitable< item >::remove_item(), rng(), and type.

Referenced by map::process_fields_in_submap(), and map::smash_items().

◆ disassembly_info()

void item::disassembly_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3174 of file item.cpp.

3176{
3178 return;
3179 }
3181 return;
3182 }
3183
3185 const requirement_data &req = dis.disassembly_requirements();
3186 if( !req.is_empty() ) {
3187 const std::string approx_time = to_string_approx( time_duration::from_turns( dis.time / 100 ) );
3188
3190 const std::string comps_str = enumerate_as_string( comps_list.begin(), comps_list.end(),
3191 []( const std::vector<item_comp> &comp_opts ) {
3192 return comp_opts.front().to_string();
3193 } );
3194
3195 std::vector<std::string> reqs_list;
3196 const requirement_data::alter_tool_comp_vector &tools_list = req.get_tools();
3197 for( const std::vector<tool_comp> &it : tools_list ) {
3198 if( !it.empty() ) {
3199 reqs_list.push_back( it.front().to_string() );
3200 }
3201 }
3203 for( const std::vector<quality_requirement> &it : quals_list ) {
3204 if( !it.empty() ) {
3205 reqs_list.push_back( it.front().to_colored_string() );
3206 }
3207 }
3208
3209 std::string descr;
3210 if( reqs_list.empty() ) {
3211 //~ 1 is approx. time (e.g. 'about 5 minutes'), 2 is a list of items
3212 descr = string_format( _( "<bold>Disassembly</bold> takes %1$s and might yield: %2$s." ),
3213 approx_time, comps_str );
3214 } else {
3215 const std::string reqs_str = enumerate_as_string( reqs_list );
3216 descr = string_format(
3217 //~ 1 is approx. time, 2 is a list of items and tools with qualities, 3 is a list of items.
3218 //~ Bold text in the middle makes it easier to see where the second list starts.
3219 _( "<bold>Disassembly</bold> takes %1$s, requires %2$s and <bold>might yield</bold>: %3$s." ),
3220 approx_time, reqs_str, comps_str );
3221 }
3222
3224 info.push_back( iteminfo( "DESCRIPTION", descr ) );
3225 }
3226}
std::string to_string_approx(const time_duration &dur, const bool verbose)
Returns approximate duration.
Definition: calendar.cpp:361
static const recipe & get_uncraft(const itype_id &id)
Returns disassembly recipe (or null recipe if no match)
Definition: recipe.h:35
requirement_data disassembly_requirements() const
If recipe can be used for disassembly fetch the combined requirements.
Definition: recipe.h:96
int time
Definition: recipe.h:61
static constexpr time_duration from_turns(const T t)
Named constructors to get a duration representing a multiple of the named time units.
Definition: calendar.h:204
@ DESCRIPTION_COMPONENTS_DISASSEMBLE
The *_vector members represent list of alternatives requirements: alter_tool_comp_vector = { * { { a,...
Definition: requirements.h:215
const alter_tool_comp_vector & get_tools() const
const alter_item_comp_vector & get_components() const
std::vector< std::vector< quality_requirement > > alter_quali_req_vector
Definition: requirements.h:222
bool is_empty() const
empty requirements are not necessary null
Definition: requirements.h:247
std::vector< std::vector< item_comp > > alter_item_comp_vector
Definition: requirements.h:223
const alter_quali_req_vector & get_qualities() const
std::vector< std::vector< tool_comp > > alter_tool_comp_vector
Definition: requirements.h:221

References _, components, DESCRIPTION_COMPONENTS_DISASSEMBLE, DESCRIPTION_COMPONENTS_MADEFROM, recipe::disassembly_requirements(), enumerate_as_string(), time_duration::from_turns(), requirement_data::get_components(), requirement_data::get_qualities(), requirement_data::get_tools(), recipe_dictionary::get_uncraft(), info(), insert_separation_line(), requirement_data::is_empty(), string_format(), iteminfo_query::test(), recipe::time, to_string_approx(), and typeId().

Referenced by info().

◆ display_money()

std::string item::display_money ( unsigned int  quantity,
unsigned int  total,
const std::optional< unsigned int > &  selected = std::nullopt 
) const

Definition at line 4799 of file item.cpp.

4801{
4802 if( selected ) {
4803 //~ This is a string to display the selected and total amount of money in a stack of cash cards.
4804 //~ %1$s is the display name of cash cards.
4805 //~ %2$s is the total amount of money.
4806 //~ %3$s is the selected amount of money.
4807 //~ Example: "cash cards $15.35 of $20.48"
4808 return string_format( pgettext( "cash card and money", "%1$s %3$s of %2$s" ), tname( quantity ),
4809 format_money( total ), format_money( *selected ) );
4810 } else {
4811 //~ This is a string to display the total amount of money in a stack of cash cards.
4812 //~ %1$s is the display name of cash cards.
4813 //~ %2$s is the total amount of money on the cash cards.
4814 //~ Example: "cash cards $20.48"
4815 return string_format( pgettext( "cash card and money", "%1$s %2$s" ), tname( quantity ),
4816 format_money( total ) );
4817 }
4818}
std::string format_money(int cents)
Definition: output.h:932
const char * pgettext(const char *context, const char *msgid)

References format_money(), pgettext(), string_format(), and tname().

Referenced by inventory_selector_preset::get_caption(), and selection_column_preset::get_caption().

◆ display_name()

std::string item::display_name ( unsigned int  quantity = 1) const

Returns the item name and the charges or contained charges (if the item can have charges at all).

Calls tname with given quantity and with_prefix being true.

Definition at line 4820 of file item.cpp.

4821{
4822 std::string name = tname( quantity );
4823 std::string sidetxt;
4824 std::string amt;
4825
4826 switch( get_side() ) {
4827 case side::BOTH:
4828 case side::num_sides:
4829 break;
4830 case side::LEFT:
4831 sidetxt = string_format( " (%s)", _( "left" ) );
4832 break;
4833 case side::RIGHT:
4834 sidetxt = string_format( " (%s)", _( "right" ) );
4835 break;
4836 }
4837 avatar &you = get_avatar();
4838 int amount = 0;
4839 int max_amount = 0;
4840 bool has_item = is_container() && contents.num_item_stacks() == 1;
4841 bool has_ammo = is_ammo_container() && contents.num_item_stacks() == 1;
4842 bool contains = has_item || has_ammo;
4843 bool show_amt = false;
4844 // We should handle infinite charges properly in all cases.
4845 if( contains ) {
4846 amount = contents.front().charges;
4848 } else if( is_book() && get_chapters() > 0 ) {
4849 // a book which has remaining unread chapters
4850 amount = get_remaining_chapters( you );
4851 } else if( ammo_capacity() > 0 ) {
4852 // anything that can be reloaded including tools, magazines, guns and auxiliary gunmods
4853 // but excluding bows etc., which have ammo, but can't be reloaded
4854 amount = ammo_remaining();
4855 max_amount = ammo_capacity();
4856 show_amt = !has_flag( flag_RELOAD_AND_SHOOT );
4857 } else if( count_by_charges() && !has_infinite_charges() ) {
4858 // A chargeable item
4859 amount = charges;
4860 max_amount = ammo_capacity();
4861 } else if( is_battery() ) {
4862 show_amt = true;
4863 amount = to_joule( energy_remaining() );
4864 max_amount = to_joule( type->battery->max_capacity );
4865 }
4866
4867 std::string ammotext;
4868 if( ( ( is_gun() && ammo_required() ) || is_magazine() ) && get_option<bool>( "AMMO_IN_NAMES" ) ) {
4869 if( !ammo_current().is_null() ) {
4870 ammotext = ammo_current()->nname( 1 );
4871 } else {
4872 ammotext = ammotype( *ammo_types().begin() )->name();
4873 }
4874 }
4875
4876 if( amount || show_amt ) {
4877 if( is_money() ) {
4878 amt = string_format( " $%.2f", amount / 100.0 );
4879 } else {
4880 if( !ammotext.empty() ) {
4881 ammotext = " " + ammotext;
4882 }
4883
4884 if( max_amount != 0 ) {
4885 amt = string_format( " (%i/%i%s)", amount, max_amount, ammotext );
4886 } else {
4887 amt = string_format( " (%i%s)", amount, ammotext );
4888 }
4889 }
4890 } else if( !ammotext.empty() ) {
4891 amt = " (" + ammotext + ")";
4892 }
4893
4894 // HACK: This is a hack to prevent possible crashing when displaying maps as items during character creation
4896 // TODO: fix point types
4897 tripoint map_pos_omt =
4898 get_var( "reveal_map_center_omt", you.global_omt_location().raw() );
4899 tripoint_abs_sm map_pos =
4900 project_to<coords::sm>( tripoint_abs_omt( map_pos_omt ) );
4901 const city *c = overmap_buffer.closest_city( map_pos ).city;
4902 if( c != nullptr ) {
4903 name = string_format( "%s %s", c->name, name );
4904 }
4905 }
4906
4907 return string_format( "%s%s%s", name, sidetxt, amt );
4908}
@ num_sides
tripoint_abs_omt global_omt_location() const
Returns the location of the player in global overmap terrain coordinates.
Definition: character.cpp:6257
constexpr Point & raw()
Definition: coordinates.h:111
bool is_ammo_container() const
Definition: item.cpp:6662
bool has_infinite_charges() const
Definition: item.cpp:9961
itype_id ammo_current() const
Specific ammo type, returns "null" if item is neither ammo nor loaded with any.
Definition: item.cpp:7564
bool is_map() const
Definition: item.cpp:6714
units::energy energy_remaining() const
Quantity of energy currently loaded in tool or battery.
Definition: item.cpp:7378
int charges_per_volume(const units::volume &vol) const
Number of (charges of) this item that fit into the given volume.
Definition: item.cpp:864
units::volume get_container_capacity() const
It returns the total capacity (volume) of the container for liquids.
Definition: item.cpp:8401
side get_side() const
Returns side item currently worn on.
Definition: item.cpp:808
int get_chapters() const
How many chapters the book has (if any).
Definition: item.cpp:7089
city_reference closest_city(const tripoint_abs_sm &center)
Find the closest city.
bool has_item(const item &it) const
Returns true if this visitable instance contains the item.
Definition: visitable.cpp:95
coords::coord_point< tripoint, coords::origin::abs, coords::omt > tripoint_abs_omt
Definition: coordinates.h:493
static const std::string flag_RELOAD_AND_SHOOT("RELOAD_AND_SHOOT")
const time_point turn_zero
Represents time point 0.
Definition: calendar.cpp:26
overmapbuffer overmap_buffer
const struct city * city
The city itself, points into overmap::cities.
Definition: overmapbuffer.h:81
Definition: overmap.h:55

References _, ammo_capacity(), ammo_current(), ammo_remaining(), ammo_required(), ammo_types(), itype::battery, BOTH, c, charges, charges_per_volume(), city_reference::city, overmapbuffer::closest_city(), contains, contents, count_by_charges(), energy_remaining(), flag_RELOAD_AND_SHOOT(), item_contents::front(), get_avatar(), get_chapters(), get_container_capacity(), get_remaining_chapters(), get_side(), get_var(), Character::global_omt_location(), has_flag(), has_infinite_charges(), visitable< item >::has_item(), is_ammo_container(), is_battery(), is_book(), is_container(), is_gun(), is_magazine(), is_map(), is_money(), is_null(), LEFT, ammunition_type::name(), om_direction::name(), itype::nname(), item_contents::num_item_stacks(), num_sides, overmap_buffer, coords::coord_point< Point, Origin, Scale >::raw(), RIGHT, string_format(), tname(), units::to_joule(), calendar::turn, calendar::turn_zero, and type.

Referenced by act_vehicle_unload_fuel(), monexamine::add_armor(), Character::apply_damage(), monexamine::attach_bag_to(), veh_interact::can_remove_part(), game_menus::inv::container_for(), inventory_selector_preset::get_caption(), selection_column_preset::get_caption(), liquid_handler::get_liquid_target(), game::handle_action(), handle_problematic_pickup(), pickup::handle_spillable_contents(), inscribe_actor::item_inscription(), game::list_items(), pick_one_up(), pickup::pick_up(), trading_window::update_win(), and musical_instrument_actor::use().

◆ display_stacked_with()

bool item::display_stacked_with ( const item rhs,
bool  check_components = false 
) const

Whether two items should stack when displayed in a inventory menu.

This is different from stacks_with, when two previously non-stackable items are now stackable and mergeable because, for example, they reaches the same temperature. This is necessary to avoid misleading stacks like "3 items-count-by-charge (5)".

Definition at line 884 of file item.cpp.

885{
886 return !count_by_charges() && stacks_with( rhs, check_components );
887}
bool stacks_with(const item &rhs, bool check_components=false, bool skip_type_check=false) const
Definition: item.cpp:889

References count_by_charges(), and stacks_with().

Referenced by pickup::stack_for_pickup_ui().

◆ dps() [1/2]

std::map< std::string, double > item::dps ( bool  for_display,
bool  for_calc 
) const

Definition at line 1443 of file item.cpp.

1444{
1445 return dps( for_display, for_calc, get_avatar() );
1446}

References dps(), and get_avatar().

◆ dps() [2/2]

std::map< std::string, double > item::dps ( bool  for_display,
bool  for_calc,
const player guy 
) const

calculate effective dps against a stock set of monsters.

by default, assume g->u is wielding for_display - include monsters intended for display purposes for_calc - include monsters intended for evaluation purposes for_display and for_calc are inclusive

Definition at line 1428 of file item.cpp.

1430{
1431 std::map<std::string, double> results;
1432 for( const std::pair<translation, dps_comp_data> &comp_mon : dps_comp_monsters ) {
1433 if( ( comp_mon.second.display != for_display ) &&
1434 ( comp_mon.second.evaluate != for_calc ) ) {
1435 continue;
1436 }
1437 monster test_mon = monster( comp_mon.second.mon_id );
1438 results[ comp_mon.first.translated() ] = effective_dps( guy, test_mon );
1439 }
1440 return results;
1441}
double effective_dps(const player &guy, const monster &mon) const
Calculate the item's effective damage per second past armor when wielded by a character against a mon...
Definition: item.cpp:1325
static const std::vector< std::pair< translation, dps_comp_data > > dps_comp_monsters
Definition: item.cpp:1421

References dps_comp_monsters, and effective_dps().

Referenced by average_dps(), combat_info(), dps(), and ideal_ranged_dps().

◆ durability_indicator()

std::string item::durability_indicator ( bool  include_intact = false) const

Provides a prefix for the durability state of the item.

with ITEM_HEALTH_BAR enabled, returns a symbol with color tag already applied. Otherwise, returns an adjective. if include_intact is true, this provides a string for the corner case of a player with ITEM_HEALTH_BAR disabled, but we need still a string for some reason.

Definition at line 6316 of file item.cpp.

6317{
6318 std::string outputstring;
6319
6320 if( damage() < 0 ) {
6321 if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
6322 outputstring = colorize( damage_symbol() + "\u00A0", damage_color() );
6323 } else if( is_gun() ) {
6324 outputstring = pgettext( "damage adjective", "accurized " );
6325 } else {
6326 outputstring = pgettext( "damage adjective", "reinforced " );
6327 }
6328 } else if( has_flag( flag_CORPSE ) ) {
6329 if( damage() > 0 ) {
6330 switch( damage_level( 4 ) ) {
6331 case 1:
6332 outputstring = pgettext( "damage adjective", "bruised " );
6333 break;
6334 case 2:
6335 outputstring = pgettext( "damage adjective", "damaged " );
6336 break;
6337 case 3:
6338 outputstring = pgettext( "damage adjective", "mangled " );
6339 break;
6340 default:
6341 outputstring = pgettext( "damage adjective", "pulped " );
6342 break;
6343 }
6344 }
6345 } else if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
6346 outputstring = colorize( damage_symbol() + "\u00A0", damage_color() );
6347 } else {
6348 outputstring = string_format( "%s ", get_base_material().dmg_adj( damage_level( 4 ) ) );
6349 if( include_intact && outputstring == " " ) {
6350 outputstring = _( "fully intact " );
6351 }
6352 }
6353
6354 return outputstring;
6355}
std::string damage_symbol() const
Provide prefix symbol for UI display dependent upon current item damage level.
Definition: item.cpp:6292
const material_type & get_base_material() const
Get the basic (main) material of this item.
Definition: item.cpp:7151
nc_color damage_color() const
Provide color for UI display dependent upon current item damage level.
Definition: item.cpp:6263

References _, colorize(), damage(), damage_color(), damage_level(), damage_symbol(), flag_CORPSE(), get_base_material(), has_flag(), is_gun(), pgettext(), and string_format().

Referenced by colorized_item_name(), damage_item(), iuse::gun_repair(), repair_item_actor::repair(), and tname().

◆ effective_dps()

double item::effective_dps ( const player guy,
const monster mon 
) const

Calculate the item's effective damage per second past armor when wielded by a character against a monster.

Definition at line 1325 of file item.cpp.

1326{
1327 const float mon_dodge = mon.get_dodge();
1328 float base_hit = guy.get_dex() / 4.0f + guy.get_hit_weapon( *this );
1329 base_hit *= std::max( 0.25f, 1.0f - guy.encumb( bp_torso ) / 100.0f );
1330 float mon_defense = mon_dodge + mon.size_melee_penalty() / 5.0;
1331 constexpr double hit_trials = 10000.0;
1332 const int rng_mean = std::max( std::min( static_cast<int>( base_hit - mon_defense ), 20 ),
1333 -20 ) + 20;
1334 double num_all_hits = hits_by_accuracy[ rng_mean ];
1335 /* critical hits have two chances to occur: triple critical hits happen much less frequently,
1336 * and double critical hits can only occur if a hit roll is more than 1.5 * monster dodge.
1337 * Not the hit roll used to determine the attack, another one.
1338 * the way the math works, some percentage of the total hits are eligible to be double
1339 * critical hits, and the rest are eligible to be triple critical hits, but in each case,
1340 * only some small percent of them actually become critical hits.
1341 */
1342 const int rng_high_mean = std::max( std::min( static_cast<int>( base_hit - 1.5 * mon_dodge ),
1343 20 ), -20 ) + 20;
1344 double num_high_hits = hits_by_accuracy[ rng_high_mean ] * num_all_hits / hit_trials;
1345 double double_crit_chance = guy.crit_chance( 4, 0, *this );
1346 double crit_chance = guy.crit_chance( 0, 0, *this );
1347 double num_low_hits = std::max( 0.0, num_all_hits - num_high_hits );
1348
1349 double moves_per_attack = guy.attack_cost( *this );
1350 // attacks that miss do no damage but take time
1351 double total_moves = ( hit_trials - num_all_hits ) * moves_per_attack;
1352 double total_damage = 0.0;
1353 double num_crits = std::min( num_low_hits * crit_chance + num_high_hits * double_crit_chance,
1354 num_all_hits );
1355 // critical hits are counted separately
1356 double num_hits = num_all_hits - num_crits;
1357 // sum average damage past armor and return the number of moves required to achieve
1358 // that damage
1359 const auto calc_effective_damage = [ &, moves_per_attack]( const double num_strikes,
1360 const bool crit, const player & guy, const monster & mon ) {
1361 monster temp_mon = mon;
1362 double subtotal_damage = 0;
1363 damage_instance base_damage;
1364 guy.roll_all_damage( crit, base_damage, true, *this );
1365 damage_instance dealt_damage = base_damage;
1366 temp_mon.absorb_hit( bodypart_id( "torso" ), dealt_damage );
1367 dealt_damage_instance dealt_dams;
1368 for( const damage_unit &dmg_unit : dealt_damage.damage_units ) {
1369 int cur_damage = 0;
1370 int total_pain = 0;
1371 temp_mon.deal_damage_handle_type( dmg_unit, bodypart_id( "torso" ), cur_damage, total_pain );
1372 if( cur_damage > 0 ) {
1373 dealt_dams.dealt_dams[ dmg_unit.type ] += cur_damage;
1374 }
1375 }
1376 double damage_per_hit = dealt_dams.total_damage();
1377 subtotal_damage = damage_per_hit * num_strikes;
1378 double subtotal_moves = moves_per_attack * num_strikes;
1379
1380 if( has_technique( rapid_strike ) ) {
1381 monster temp_rs_mon = mon;
1382 damage_instance rs_base_damage;
1383 guy.roll_all_damage( crit, rs_base_damage, true, *this );
1384 damage_instance dealt_rs_damage = rs_base_damage;
1385 for( damage_unit &dmg_unit : dealt_rs_damage.damage_units ) {
1386 dmg_unit.damage_multiplier *= 0.66;
1387 }
1388 temp_rs_mon.absorb_hit( bodypart_id( "torso" ), dealt_rs_damage );
1389 dealt_damage_instance rs_dealt_dams;
1390 for( const damage_unit &dmg_unit : dealt_rs_damage.damage_units ) {
1391 int cur_damage = 0;
1392 int total_pain = 0;
1393 temp_rs_mon.deal_damage_handle_type( dmg_unit, bodypart_id( "torso" ), cur_damage, total_pain );
1394 if( cur_damage > 0 ) {
1395 rs_dealt_dams.dealt_dams[ dmg_unit.type ] += cur_damage;
1396 }
1397 }
1398 double rs_damage_per_hit = rs_dealt_dams.total_damage();
1399 subtotal_moves *= 0.5;
1400 subtotal_damage *= 0.5;
1401 subtotal_moves += moves_per_attack * num_strikes * 0.33;
1402 subtotal_damage += rs_damage_per_hit * num_strikes * 0.5;
1403 }
1404 return std::make_pair( subtotal_moves, subtotal_damage );
1405 };
1406 std::pair<double, double> crit_summary = calc_effective_damage( num_crits, true, guy, mon );
1407 total_moves += crit_summary.first;
1408 total_damage += crit_summary.second;
1409 std::pair<double, double> summary = calc_effective_damage( num_hits, false, guy, mon );
1410 total_moves += summary.first;
1411 total_damage += summary.second;
1412 return total_damage * to_moves<double>( 1_seconds ) / total_moves;
1413}
int_id< body_part_type > bodypart_id
Definition: bodypart.h:23
virtual int get_dex() const
Definition: character.cpp:4082
float get_hit_weapon(const item &weap) const
Gets melee accuracy component from weapon+skills.
Definition: melee.cpp:306
int encumb(body_part bp) const
Returns ENC provided by armor, etc.
Definition: character.cpp:4015
int size_melee_penalty() const
Definition: creature.cpp:483
bool has_technique(const matec_id &tech) const
Whether the item supports a specific martial art technique (either through its type,...
Definition: item.cpp:5439
void deal_damage_handle_type(const damage_unit &du, bodypart_id bp, int &damage, int &pain) override
Definition: monster.cpp:1621
float get_dodge() const override
Definition: monster.cpp:2002
void absorb_hit(const bodypart_id &bp, damage_instance &dam) override
Definition: monster.cpp:1404
Definition: player.h:84
static const double hits_by_accuracy[41]
Definition: item.cpp:1313
static const matec_id rapid_strike("RAPID")
damage_type type
Definition: damage.h:36
float damage_multiplier
Definition: damage.h:40
std::array< int, NUM_DT > dealt_dams
Definition: damage.h:86
int total_damage() const
Definition: damage.cpp:180

References monster::absorb_hit(), Character::attack_cost(), bp_torso, Character::crit_chance(), damage_unit::damage_multiplier, damage_instance::damage_units, monster::deal_damage_handle_type(), dealt_damage_instance::dealt_dams, Character::encumb(), Character::get_dex(), monster::get_dodge(), Character::get_hit_weapon(), has_technique(), hits_by_accuracy, rapid_strike, Character::roll_all_damage(), Creature::size_melee_penalty(), dealt_damage_instance::total_damage(), and damage_unit::type.

Referenced by dps().

◆ energy_remaining()

units::energy item::energy_remaining ( ) const

Quantity of energy currently loaded in tool or battery.

Definition at line 7378 of file item.cpp.

7379{
7380 if( is_battery() ) {
7381 return energy;
7382 }
7383
7384 return 0_J;
7385}
units::energy energy
Definition: item.h:2204

References energy, and is_battery().

Referenced by display_name(), mod_energy(), process_vehicle_items(), and charger_tile::update_internal().

◆ engine_displacement()

int item::engine_displacement ( ) const

for combustion engines the displacement (cc)

Definition at line 4117 of file item.cpp.

4118{
4119 return type->engine ? type->engine->displacement : 0;
4120}
cata::value_ptr< islot_engine > engine
Definition: itype.h:856

References itype::engine, and type.

Referenced by veh_interact::display_details(), vehicle_part::name(), vehicle::part_vpower_w(), and tname().

◆ erase_var()

void item::erase_var ( const std::string &  name)

◆ faults_potential()

std::set< fault_id > item::faults_potential ( ) const

What faults can potentially occur with this item?

Definition at line 6804 of file item.cpp.

6805{
6806 std::set<fault_id> res;
6807 res.insert( type->faults.begin(), type->faults.end() );
6808 return res;
6809}
std::set< fault_id > faults
What faults (if any) can occur.
Definition: itype.h:1017

References itype::faults, and type.

Referenced by vehicle_part::faults_potential(), ranged::handle_gun_damage(), and examine_item_menu::rate_action_mend().

◆ fill_with()

void item::fill_with ( item liquid,
int  amount = INFINITE_CHARGES 
)

Fill item with liquid up to its capacity.

This works for guns and tools that accept liquid ammo.

Parameters
liquidLiquid to fill the container with.
amountAmount to fill item with, capped by remaining capacity

Definition at line 8568 of file item.cpp.

8569{
8570 amount = std::min( get_remaining_capacity_for_liquid( liquid, true ),
8571 std::min( amount, liquid.charges ) );
8572 if( amount <= 0 ) {
8573 return;
8574 }
8575
8576 if( !is_container() ) {
8577 if( !is_reloadable_with( liquid.typeId() ) ) {
8578 debugmsg( "Tried to fill %s which is not a container and can't be reloaded with %s.",
8579 tname(), liquid.tname() );
8580 return;
8581 }
8582 ammo_set( liquid.typeId(), ammo_remaining() + amount );
8583 } else if( is_food_container() ) {
8584 item &cts = contents.front();
8585 // Use maximum rot between the two
8586 cts.set_relative_rot( std::max( cts.get_relative_rot(),
8587 liquid.get_relative_rot() ) );
8588 cts.mod_charges( amount );
8589 } else if( !is_container_empty() ) {
8590 // if container already has liquid we need to set the amount
8591 item &cts = contents.front();
8592 cts.mod_charges( amount );
8593 } else {
8594 item liquid_copy( liquid );
8595 liquid_copy.charges = amount;
8596 put_in( liquid_copy );
8597 }
8598
8599 liquid.mod_charges( -amount );
8601}
bool is_reloadable_with(const itype_id &ammo) const
Returns true if this item can be reloaded with specified ammo type at this moment.
Definition: item.cpp:6871
void mod_charges(int mod)
Modify the charges of this item, only use for items counted by charges! The item must have enough cha...
Definition: item.cpp:9721
void on_contents_changed()
Callback when contents of the item are affected in any way other than just processing.
Definition: item.cpp:4538
int get_remaining_capacity_for_liquid(const item &liquid, bool allow_bucket=false, std::string *err=nullptr) const
How much more of this liquid (in charges) can be put in this container.
Definition: item.cpp:8430

References ammo_remaining(), ammo_set(), charges, contents, debugmsg, item_contents::front(), get_relative_rot(), get_remaining_capacity_for_liquid(), is_container(), is_container_empty(), is_food_container(), is_reloadable_with(), mod_charges(), on_contents_changed(), put_in(), set_relative_rot(), tname(), and typeId().

Referenced by veh_interact::complete_vehicle(), vehicle_part::fill_with(), advanced_inventory::move_content(), Character::pour_into(), and reload().

◆ final_info()

void item::final_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3626 of file item.cpp.

3628{
3629 if( is_null() ) {
3630 return;
3631 }
3632
3633 // TODO: Remove
3634 const iteminfo_query *parts = &parts_ref;
3635
3636 const std::string space = " ";
3637
3639
3640 if( parts->test( iteminfo_parts::BASE_RIGIDITY ) ) {
3641 if( !type->rigid ) {
3642 info.emplace_back( "BASE",
3643 _( "* This item is <info>not rigid</info>. Its"
3644 " volume and encumbrance increase with contents." ) );
3645 }
3646 }
3647
3649 if( !conductive() ) {
3650 info.push_back( iteminfo( "BASE", _( "* This item <good>does not "
3651 "conduct</good> electricity." ) ) );
3652 } else if( has_flag( flag_CONDUCTIVE ) ) {
3653 info.push_back( iteminfo( "BASE",
3654 _( "* This item effectively <bad>conducts</bad> "
3655 "electricity, as it has no guard." ) ) );
3656 } else {
3657 info.push_back( iteminfo( "BASE", _( "* This item <bad>conducts</bad> electricity." ) ) );
3658 }
3659 }
3660
3661 avatar &you = get_avatar();
3662 if( is_armor() && you.has_trait( trait_WOOLALLERGY ) &&
3663 ( made_of( material_id( "wool" ) ) || has_own_flag( "wooled" ) ) ) {
3664 info.push_back( iteminfo( "DESCRIPTION",
3665 _( "* This clothing will give you an <bad>allergic "
3666 "reaction</bad>." ) ) );
3667 }
3668
3669 if( parts->test( iteminfo_parts::DESCRIPTION_FLAGS ) ) {
3670 // concatenate base and acquired flags...
3671 std::vector<std::string> flags;
3672 std::set_union( type->get_flags().begin(), type->get_flags().end(),
3673 get_flags().begin(), get_flags().end(),
3674 std::back_inserter( flags ) );
3675
3676 // ...and display those which have an info description
3677 for( const std::string &e : flags ) {
3678 const json_flag &f = json_flag::get( e );
3679 if( !f.info().empty() ) {
3680 info.emplace_back( "DESCRIPTION", string_format( "* %s", _( f.info() ) ) );
3681 }
3682 }
3683 }
3684
3685 armor_fit_info( info, parts, batch, debug );
3686
3687 if( is_tool() ) {
3689 info.push_back( iteminfo( "DESCRIPTION",
3690 _( "* This tool can draw power from a <info>Bionic Armor Interface</info>" ) ) );
3691 }
3693 info.push_back( iteminfo( "DESCRIPTION",
3694 _( "* This tool uses a <info>universal power supply</info> "
3695 "and is <neutral>not compatible</neutral> with "
3696 "<info>standard batteries</info>." ) ) );
3697 } else if( has_flag( flag_RECHARGE ) && has_flag( flag_NO_RELOAD ) &&
3699 info.push_back( iteminfo( "DESCRIPTION",
3700 _( "* This tool has a <info>rechargeable power cell</info> "
3701 "and is <neutral>not compatible</neutral> with "
3702 "<info>standard batteries</info>." ) ) );
3703 } else if( has_flag( flag_RECHARGE ) &&
3705 info.push_back( iteminfo( "DESCRIPTION",
3706 _( "* This tool has a <info>rechargeable power cell</info> "
3707 "and can be recharged in any <neutral>UPS-compatible "
3708 "recharging station</neutral>. You could charge it with "
3709 "<info>standard batteries</info>, but unloading it is "
3710 "impossible." ) ) );
3711 } else if( has_flag( flag_USES_BIONIC_POWER ) ) {
3712 info.emplace_back( "DESCRIPTION",
3713 _( "* This tool <info>runs on bionic power</info>." ) );
3714 }
3715 }
3716
3719 if( has_flag( flag_RADIO_MOD ) ) {
3720 info.emplace_back( "DESCRIPTION",
3721 _( "* This item has been modified to listen to <info>radio "
3722 "signals</info>. It can still be activated manually." ) );
3723 } else {
3724 info.emplace_back( "DESCRIPTION",
3725 _( "* This item can only be activated by a <info>radio "
3726 "signal</info>." ) );
3727 }
3728
3729 std::string signame;
3730 if( has_flag( flag_RADIOSIGNAL_1 ) ) {
3731 signame = "<color_c_red>red</color> radio signal.";
3732 } else if( has_flag( flag_RADIOSIGNAL_2 ) ) {
3733 signame = "<color_c_blue>blue</color> radio signal.";
3734 } else if( has_flag( flag_RADIOSIGNAL_3 ) ) {
3735 signame = "<color_c_green>green</color> radio signal.";
3736 }
3738 info.emplace_back( "DESCRIPTION",
3739 string_format( _( "* It will be activated by the %s." ),
3740 signame ) );
3741 }
3742
3745 info.emplace_back( "DESCRIPTION",
3746 _( "* Activating this item with a <info>radio signal</info> will "
3747 "<neutral>detonate</neutral> it immediately." ) );
3748 }
3749 }
3750
3751 bionic_info( info, parts, batch, debug );
3752
3753 if( is_gun() && has_flag( flag_FIRE_TWOHAND ) &&
3755 info.push_back( iteminfo( "DESCRIPTION",
3756 _( "* This weapon needs <info>two free hands</info> "
3757 "to fire." ) ) );
3758 }
3759
3762 info.push_back( iteminfo( "DESCRIPTION",
3763 _( "* This mod <bad>obscures sights</bad> of the "
3764 "base weapon." ) ) );
3765 }
3766
3767 if( is_gunmod() && has_flag( flag_CONSUMABLE ) &&
3769 info.push_back( iteminfo( "DESCRIPTION",
3770 _( "* This mod might <bad>suffer wear</bad> when firing "
3771 "the base weapon." ) ) );
3772 }
3773
3776 info.push_back( iteminfo( "DESCRIPTION",
3777 _( "* The casing of this item has <neutral>cracked</neutral>, "
3778 "revealing an <info>ominous green glow</info>." ) ) );
3779 }
3780
3783 info.push_back( iteminfo( "DESCRIPTION",
3784 _( "* This object is <neutral>surrounded</neutral> by a "
3785 "<info>sickly green glow</info>." ) ) );
3786 }
3787
3788 if( is_brewable() || ( !contents.empty() && contents.front().is_brewable() ) ) {
3789 const item &brewed = !is_brewable() ? contents.front() : *this;
3791 const time_duration btime = brewed.brewing_time();
3792 int btime_i = to_days<int>( btime );
3793 if( btime <= 2_days ) {
3794 btime_i = to_hours<int>( btime );
3795 info.push_back( iteminfo( "DESCRIPTION",
3796 string_format( vgettext( "* Once set in a vat, this "
3797 "will ferment in around %d hour.",
3798 "* Once set in a vat, this will ferment in "
3799 "around %d hours.", btime_i ), btime_i ) ) );
3800 } else {
3801 info.push_back( iteminfo( "DESCRIPTION",
3802 string_format( vgettext( "* Once set in a vat, this "
3803 "will ferment in around %d day.",
3804 "* Once set in a vat, this will ferment in "
3805 "around %d days.", btime_i ), btime_i ) ) );
3806 }
3807 }
3809 for( const itype_id &res : brewed.brewing_results() ) {
3810 info.push_back( iteminfo( "DESCRIPTION",
3811 string_format( _( "* Fermenting this will produce "
3812 "<neutral>%s</neutral>." ),
3813 nname( res, brewed.charges ) ) ) );
3814 }
3815 }
3816 }
3817
3819 for( const fault_id &e : faults ) {
3820 //~ %1$s is the name of a fault and %2$s is the description of the fault
3821 info.emplace_back( "DESCRIPTION", string_format( _( "* <bad>%1$s</bad>. %2$s" ),
3822 e.obj().name(), e.obj().description() ) );
3823 }
3824 }
3825
3826 // does the item fit in any holsters?
3827 std::vector<const itype *> holsters = item_controller->find( [this]( const itype & e ) {
3828 if( !e.can_use( "holster" ) ) {
3829 return false;
3830 }
3831 const holster_actor *ptr = dynamic_cast<const holster_actor *>
3832 ( e.get_use( "holster" )->get_actor_ptr() );
3833 return ptr->can_holster( *this );
3834 } );
3835
3836 if( !holsters.empty() && parts->test( iteminfo_parts::DESCRIPTION_HOLSTERS ) ) {
3838 info.emplace_back( "DESCRIPTION", _( "<bold>Can be stored in</bold>: " ) +
3839 enumerate_as_string( holsters.begin(), holsters.end(),
3840 []( const itype * e ) {
3841 return e->nname( 1 );
3842 } ) );
3843 }
3844
3846 for( auto &u : type->use_methods ) {
3847 const delayed_transform_iuse *tt = dynamic_cast<const delayed_transform_iuse *>
3848 ( u.second.get_actor_ptr() );
3849 if( tt == nullptr ) {
3850 continue;
3851 }
3852 const int time_to_do = tt->time_to_do( *this );
3853 if( time_to_do <= 0 ) {
3854 info.push_back( iteminfo( "DESCRIPTION",
3855 _( "It's done and <info>can be activated</info>." ) ) );
3856 } else {
3857 const std::string time = to_string_clipped( time_duration::from_turns( time_to_do ) );
3858 info.push_back( iteminfo( "DESCRIPTION",
3859 string_format( _( "It will be done in %s." ),
3860 time.c_str() ) ) );
3861 }
3862 }
3863 }
3864
3865 std::map<std::string, std::string>::const_iterator item_note = item_vars.find( "item_note" );
3866 std::map<std::string, std::string>::const_iterator item_note_tool =
3867 item_vars.find( "item_note_tool" );
3868
3869 if( item_note != item_vars.end() && parts->test( iteminfo_parts::DESCRIPTION_NOTES ) ) {
3871 std::string ntext;
3872 const inscribe_actor *use_actor = nullptr;
3873 if( item_note_tool != item_vars.end() ) {
3874 const use_function *use_func = itype_id( item_note_tool->second )->get_use( "inscribe" );
3875 use_actor = dynamic_cast<const inscribe_actor *>( use_func->get_actor_ptr() );
3876 }
3877 if( use_actor ) {
3878 //~ %1$s: gerund (e.g. carved), %2$s: item name, %3$s: inscription text
3879 ntext = string_format( pgettext( "carving", "%1$s on the %2$s is: %3$s" ),
3880 use_actor->gerund, tname(), item_note->second );
3881 } else {
3882 //~ %1$s: inscription text
3883 ntext = string_format( pgettext( "carving", "Note: %1$s" ), item_note->second );
3884 }
3885 info.push_back( iteminfo( "DESCRIPTION", ntext ) );
3886 }
3887
3888 if( this->get_var( "die_num_sides", 0 ) != 0 ) {
3889 info.emplace_back( "DESCRIPTION",
3890 string_format( _( "* This item can be used as a <info>die</info>, "
3891 "and has <info>%d</info> sides." ),
3892 static_cast<int>( this->get_var( "die_num_sides",
3893 0 ) ) ) );
3894 }
3895
3896 // Price and barter value
3897 const int price_preapoc = price( false ) * batch;
3898 const int price_postapoc = price( true ) * batch;
3899 if( parts->test( iteminfo_parts::BASE_PRICE ) ) {
3901 info.push_back( iteminfo( "BASE", _( "Price: " ), _( "$<num>" ),
3903 static_cast<double>( price_preapoc ) / 100 ) );
3904 }
3905 if( price_preapoc != price_postapoc && parts->test( iteminfo_parts::BASE_BARTER ) ) {
3906 info.push_back( iteminfo( "BASE", space + _( "Barter value: " ), _( "$<num>" ),
3908 static_cast<double>( price_postapoc ) / 100 ) );
3909 }
3910
3911 // Recipes using this item as an ingredient
3913 itype_id tid = contents.empty() ? typeId() : contents.front().typeId();
3914 const inventory &crafting_inv = you.crafting_inventory();
3915
3916 const recipe_subset available_recipe_subset = you.get_available_recipes( crafting_inv, nullptr,
3918 const std::set<const recipe *> &item_recipes = available_recipe_subset.of_component( tid );
3919
3920 if( item_recipes.empty() ) {
3922 info.push_back( iteminfo( "DESCRIPTION",
3923 _( "You know of nothing you could craft with it." ) ) );
3924 } else {
3925 if( item_recipes.size() > 24 ) {
3927 info.push_back( iteminfo( "DESCRIPTION",
3928 _( "You know dozens of things you could craft with it." ) ) );
3929 } else if( item_recipes.size() > 12 ) {
3931 info.push_back( iteminfo( "DESCRIPTION",
3932 _( "You could use it to craft various other things." ) ) );
3933 } else {
3934 // Extract item names from recipes and sort them
3935 std::vector<std::pair<std::string, bool>> result_names;
3937 item_recipes.begin(), item_recipes.end(),
3938 std::back_inserter( result_names ),
3939 [&crafting_inv]( const recipe * r ) {
3940 bool can_make = r->deduped_requirements().can_make_with_inventory(
3941 crafting_inv, r->get_component_filter() );
3942 return std::make_pair( r->result_name(), can_make );
3943 } );
3944 std::sort( result_names.begin(), result_names.end(), localized_compare );
3945 const std::string recipes =
3946 enumerate_as_string( result_names.begin(), result_names.end(),
3947 []( const std::pair<std::string, bool> &p ) {
3948 if( p.second ) {
3949 return p.first;
3950 } else {
3951 return string_format( "<dark>%s</dark>", p.first );
3952 }
3953 } );
3955 info.push_back( iteminfo( "DESCRIPTION",
3956 string_format( _( "You could use it to craft: %s" ),
3957 recipes ) ) );
3958 }
3959 }
3960 }
3961 if( get_option<bool>( "ENABLE_ASCII_ART_ITEM" ) ) {
3962 const ascii_art_id art = type->picture_id;
3963 if( art.is_valid() ) {
3964 for( const std::string &line : art->picture ) {
3965 info.push_back( iteminfo( "DESCRIPTION", line ) );
3966 }
3967 }
3968 }
3969}
static std::string to_string_clipped(const int num, const clipped_unit type, const clipped_align align)
Definition: calendar.cpp:228
const inventory & crafting_inventory(bool clear_path)
Definition: crafting.cpp:556
std::vector< std::string > picture
Definition: ascii_art.h:22
iterator begin() const
Definition: flat_set.h:83
iterator end() const
Definition: flat_set.h:86
This is a iuse_transform that uses the age of the item instead of a counter.
Definition: iuse_actor.h:289
int time_to_do(const item &it) const
How much longer (in turns) until the transformation can be done, can be negative.
Definition: iuse_actor.cpp:882
Writes on stuff (ground or items)
Definition: iuse_actor.h:610
translation gerund
Definition: iuse_actor.h:633
const FlagsSetType & get_flags() const
returs read-only set of flags of this item (not including flags from item type or gunmods)
Definition: item.cpp:5353
const std::vector< itype_id > & brewing_results() const
The results of fermenting this item.
Definition: item.cpp:5951
std::set< fault_id > faults
What faults (if any) currently apply to this item.
Definition: item.h:2168
time_duration brewing_time() const
Time for this item to be fully fermented.
Definition: item.cpp:5946
bool conductive() const
Whether the items is conductive.
Definition: item.cpp:6478
void bionic_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3275
int price(bool practical) const
Returns the monetary value of an item.
Definition: item.cpp:4921
void armor_fit_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2740
Definition: flag.h:15
std::string info() const
Get informative text for display in UI.
Definition: flag.h:30
recipe_subset get_available_recipes(const inventory &crafting_inv, const std::vector< npc * > *helpers=nullptr, recipe_filter filter=nullptr) const
Returns all available recipes (from books and npc companions)
Definition: player.cpp:295
const std::set< const recipe * > & of_component(const itype_id &id) const
Returns all recipes which could use component.
static const std::string flag_RADIOSIGNAL_2("RADIOSIGNAL_2")
static const std::string flag_FIRE_TWOHAND("FIRE_TWOHAND")
static const std::string flag_RADIOSIGNAL_1("RADIOSIGNAL_1")
static const std::string flag_DISABLE_SIGHTS("DISABLE_SIGHTS")
static const std::string flag_USE_UPS("USE_UPS")
static const std::string flag_RECHARGE("RECHARGE")
static const std::string flag_RADIO_ACTIVATION("RADIO_ACTIVATION")
static const std::string flag_RADIO_INVOKE_PROC("RADIO_INVOKE_PROC")
static const std::string flag_CONSUMABLE("CONSUMABLE")
static const std::string flag_NO_RELOAD("NO_RELOAD")
static const std::string flag_RADIOSIGNAL_3("RADIOSIGNAL_3")
static const std::string flag_LEAK_ALWAYS("LEAK_ALWAYS")
static const std::string flag_RADIO_MOD("RADIO_MOD")
std::unique_ptr< Item_factory > item_controller
@ DESCRIPTION_RECHARGE_UPSCAPABLE
@ DESCRIPTION_GUNMOD_DISABLESSIGHTS
@ DESCRIPTION_BREWABLE_DURATION
@ DESCRIPTION_RADIO_ACTIVATION_CHANNEL
@ DESCRIPTION_BREWABLE_PRODUCTS
@ DESCRIPTION_RECHARGE_NORELOAD
@ DESCRIPTION_ACTIVATABLE_TRANSFORMATION
@ DESCRIPTION_BIONIC_ARMOR_INTERFACE
@ DESCRIPTION_RADIOACTIVITY_DAMAGED
@ DESCRIPTION_RADIO_ACTIVATION_PROC
@ DESCRIPTION_RECHARGE_UPSMODDED
@ DESCRIPTION_GUNMOD_CONSUMABLE
@ DESCRIPTION_RADIOACTIVITY_ALWAYS
@ DESCRIPTION_RADIO_ACTIVATION
@ DESCRIPTION_APPLICABLE_RECIPES
void line(map *m, const ter_id &type, point p1, point p2)
Definition: mapgen.cpp:6281
void transform(player &p, const tripoint &pos)
Transform the examined object into the object specified by its transforms_into property.
Definition: iexamine.cpp:1641
recipe_filter recipe_filter_by_component(const itype_id &c)
ascii_art_id picture_id
Definition: itype.h:909
constexpr localized_comparator localized_compare
Definition: translations.h:342

References _, armor_fit_info(), BASE_BARTER, BASE_PRICE, BASE_RIGIDITY, cata::flat_set< T, Compare, Data >::begin(), bionic_info(), brewing_results(), brewing_time(), itype::can_use(), charges, conductive(), contents, Character::crafting_inventory(), damage(), debug, DESCRIPTION_ACTIVATABLE_TRANSFORMATION, DESCRIPTION_APPLICABLE_RECIPES, DESCRIPTION_BIONIC_ARMOR_INTERFACE, DESCRIPTION_BREWABLE_DURATION, DESCRIPTION_BREWABLE_PRODUCTS, DESCRIPTION_CONDUCTIVITY, DESCRIPTION_FAULTS, DESCRIPTION_FLAGS, DESCRIPTION_GUNMOD_CONSUMABLE, DESCRIPTION_GUNMOD_DISABLESSIGHTS, DESCRIPTION_HOLSTERS, DESCRIPTION_NOTES, DESCRIPTION_RADIO_ACTIVATION, DESCRIPTION_RADIO_ACTIVATION_CHANNEL, DESCRIPTION_RADIO_ACTIVATION_PROC, DESCRIPTION_RADIOACTIVITY_ALWAYS, DESCRIPTION_RADIOACTIVITY_DAMAGED, DESCRIPTION_RECHARGE_NORELOAD, DESCRIPTION_RECHARGE_UPSCAPABLE, DESCRIPTION_RECHARGE_UPSMODDED, DESCRIPTION_TWOHANDED, item_contents::empty(), cata::flat_set< T, Compare, Data >::end(), enumerate_as_string(), faults, flag_CONDUCTIVE(), flag_CONSUMABLE(), flag_DISABLE_SIGHTS(), flag_FIRE_TWOHAND(), flag_LEAK_ALWAYS(), flag_LEAK_DAM(), flag_NO_RELOAD(), flag_RADIO_ACTIVATION(), flag_RADIO_INVOKE_PROC(), flag_RADIO_MOD(), flag_RADIOACTIVE(), flag_RADIOSIGNAL_1(), flag_RADIOSIGNAL_2(), flag_RADIOSIGNAL_3(), flag_RECHARGE(), flag_USE_UPS(), flag_USES_BIONIC_POWER(), time_duration::from_turns(), item_contents::front(), inscribe_actor::gerund, json_flag::get(), use_function::get_actor_ptr(), player::get_available_recipes(), get_avatar(), get_flags(), itype::get_flags(), itype::get_use(), get_var(), has_flag(), has_own_flag(), Character::has_trait(), json_flag::info(), info(), insert_separation_line(), is_armor(), is_brewable(), iteminfo::is_decimal, is_gun(), is_gunmod(), is_null(), is_power_armor(), is_tool(), item_controller, item_vars, itype_id, localized_compare, iteminfo::lower_is_better, made_of(), nname(), iteminfo::no_newline, recipe_subset::of_component(), pgettext(), price(), ptr(), recipe_filter_by_component(), itype::rigid, sign::space, string_format(), iteminfo_query::test(), time, delayed_transform_iuse::time_to_do(), tname(), to_string_clipped(), trait_WOOLALLERGY, iexamine::transform(), type, typeId(), itype::use_methods, and vgettext().

Referenced by info().

◆ find_armor_data()

const islot_armor * item::find_armor_data ( ) const

If this is an armor item, return its armor data.

You should probably not use this function, use the various functions above (like get_storage) to access armor data directly.

Definition at line 6682 of file item.cpp.

6683{
6684 if( type->armor ) {
6685 return &*type->armor;
6686 }
6687 // Currently the only way to make a non-armor item into armor is to install a gun mod.
6688 // The gunmods are stored in the items contents, as are the contents of a container, and the
6689 // tools in a tool belt (a container actually), or the ammo in a quiver (container again).
6690 for( const item *mod : gunmods() ) {
6691 if( mod->type->armor ) {
6692 return &*mod->type->armor;
6693 }
6694 }
6695 return nullptr;
6696}
cata::value_ptr< islot_armor > armor
Definition: itype.h:852

References itype::armor, gunmods(), and type.

Referenced by get_base_env_resist(), get_base_env_resist_w_filter(), get_coverage(), get_covered_body_parts(), get_encumber(), get_encumber_when_containing(), get_env_resist(), get_storage(), get_thickness(), get_warmth(), get_weight_capacity_bonus(), get_weight_capacity_modifier(), is_armor(), and is_sided().

◆ fire_resist()

int item::fire_resist ( bool  to_self = false,
int  base_env_resist = 0 
) const

Definition at line 6161 of file item.cpp.

6162{
6163 if( to_self ) {
6164 // Fire damages items in a different way
6165 return INT_MAX;
6166 }
6167
6168 float resist = 0.0;
6170 if( is_null() ) {
6171 return 0.0;
6172 }
6173
6174 const std::vector<const material_type *> mat_types = made_of_types();
6175 if( !mat_types.empty() ) {
6176 for( const material_type *mat : mat_types ) {
6177 resist += mat->fire_resist();
6178 }
6179 // Average based on number of materials.
6180 resist /= mat_types.size();
6181 }
6182
6183 const int env = get_env_resist( base_env_resist );
6184 if( env < 10 ) {
6185 // Iron resists immersion in magma, iron-clad knight won't.
6186 resist *= env / 10.0f;
6187 }
6188
6189 return std::lround( resist + mod );
6190}
@ clothing_mod_type_fire
Definition: clothing_mod.h:18

References clothing_mod_type_fire, get_clothing_mod_val(), get_env_resist(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ flammable()

bool item::flammable ( int  threshold = 0) const

Whether the items is flammable.

(Make sure to keep this in sync with fire code in fields.cpp)

Parameters
thresholdItem is flammable if it provides more fuel than threshold.

Definition at line 8321 of file item.cpp.

8322{
8323 const std::vector<const material_type *> &mats = made_of_types();
8324 if( mats.empty() ) {
8325 // Don't know how to burn down something made of nothing.
8326 return false;
8327 }
8328
8329 int flammability = 0;
8330 units::volume volume_per_turn = 0_ml;
8331 for( const material_type *m : mats ) {
8332 const mat_burn_data &bd = m->burn_data( 1 );
8333 if( bd.immune ) {
8334 // Made to protect from fire
8335 return false;
8336 }
8337
8338 flammability += bd.fuel;
8339 volume_per_turn += bd.volume_per_turn;
8340 }
8341
8342 if( threshold == 0 || flammability <= 0 ) {
8343 return flammability > 0;
8344 }
8345
8346 volume_per_turn /= mats.size();
8347 units::volume vol = base_volume();
8348 if( volume_per_turn > 0_ml && volume_per_turn < vol ) {
8349 flammability = flammability * volume_per_turn / vol;
8350 } else {
8351 // If it burns well, it provides a bonus here
8352 flammability *= vol / units::legacy_volume_factor;
8353 }
8354
8355 return flammability > threshold;
8356}
Contains burning parameters for a given material.
Definition: fire.h:46
bool immune
If this is true, an object will not burn or be destroyed by fire.
Definition: fire.h:48
units::volume volume_per_turn
If non-zero and lower than item's volume, scale burning by volume_penalty / volume.
Definition: fire.h:50
float fuel
Fuel contributed per tick when this material burns.
Definition: fire.h:52

References base_volume(), mat_burn_data::fuel, mat_burn_data::immune, units::legacy_volume_factor, made_of_types(), and mat_burn_data::volume_per_turn.

Referenced by Character::can_feed_furnace_with(), behavior::character_oracle_t::can_make_fire(), and monster::process_turn().

◆ food_info()

void item::food_info ( const item food_item,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug,
temperature_flag  temperature 
) const
Survival >=3 allows detection of poisonous food Survival >=5 allows detection of hallucinogenic food

Definition at line 1670 of file item.cpp.

1673{
1674 nutrients min_nutr;
1675 nutrients max_nutr;
1676 avatar &you = get_avatar();
1677
1678 std::string recipe_exemplar = get_var( "recipe_exemplar", "" );
1679 if( recipe_exemplar.empty() ) {
1680 min_nutr = max_nutr = you.compute_effective_nutrients( *food_item );
1681 } else {
1682 std::tie( min_nutr, max_nutr ) =
1683 you.compute_nutrient_range( *food_item, recipe_id( recipe_exemplar ) );
1684 }
1685
1686 bool show_nutr = parts->test( iteminfo_parts::FOOD_NUTRITION ) ||
1688 if( min_nutr != max_nutr && show_nutr ) {
1689 info.emplace_back(
1690 "FOOD", _( "Nutrition will <color_cyan>vary with chosen ingredients</color>." ) );
1691 if( recipe_dict.is_item_on_loop( food_item->typeId() ) ) {
1692 info.emplace_back(
1693 "FOOD", _( "Nutrition range cannot be calculated accurately due to "
1694 "<color_red>recipe loops</color>." ) );
1695 }
1696 }
1697
1698 const std::string space = " ";
1699 if( max_nutr.kcal != 0 || food_item->get_comestible()->quench != 0 ) {
1700 if( parts->test( iteminfo_parts::FOOD_NUTRITION ) ) {
1701 info.push_back( iteminfo( "FOOD", _( "<bold>Calories (kcal)</bold>: " ),
1702 "", iteminfo::no_newline, min_nutr.kcal ) );
1703 if( max_nutr.kcal != min_nutr.kcal ) {
1704 info.push_back( iteminfo( "FOOD", _( "-" ),
1705 "", iteminfo::no_newline, max_nutr.kcal ) );
1706 }
1707 }
1708 if( parts->test( iteminfo_parts::FOOD_QUENCH ) ) {
1709 info.push_back( iteminfo( "FOOD", space + _( "Quench: " ),
1710 food_item->get_comestible()->quench ) );
1711 }
1712 }
1713
1714 const std::pair<int, int> fun_for_food_item = you.fun_for( *food_item );
1715 if( fun_for_food_item.first != 0 && parts->test( iteminfo_parts::FOOD_JOY ) ) {
1716 info.push_back( iteminfo( "FOOD", _( "Enjoyability: " ), fun_for_food_item.first ) );
1717 }
1718
1719 if( parts->test( iteminfo_parts::FOOD_PORTIONS ) ) {
1720 info.push_back( iteminfo( "FOOD", _( "Portions: " ),
1721 std::abs( static_cast<int>( food_item->charges ) * batch ) ) );
1722 }
1723 if( food_item->corpse != nullptr && parts->test( iteminfo_parts::FOOD_SMELL ) &&
1724 ( debug || ( g != nullptr && ( you.has_trait( trait_CARNIVORE ) ||
1726 info.push_back( iteminfo( "FOOD", _( "Smells like: " ) + food_item->corpse->nname() ) );
1727 }
1728
1729 auto format_vitamin = [&]( const std::pair<vitamin_id, int> &v, bool display_vitamins ) {
1730 const bool is_vitamin = v.first->type() == vitamin_type::VITAMIN;
1731 // only display vitamins that we actually require
1732 if( you.vitamin_rate( v.first ) == 0_turns || v.second == 0 ||
1733 display_vitamins != is_vitamin || v.first->has_flag( flag_NO_DISPLAY ) ) {
1734 return std::string();
1735 }
1736 const double multiplier = you.vitamin_rate( v.first ) / 1_days * 100;
1737 const int min_value = min_nutr.get_vitamin( v.first );
1738 const int max_value = v.second;
1739 const int min_rda = std::lround( min_value * multiplier );
1740 const int max_rda = std::lround( max_value * multiplier );
1741 const std::string format = min_rda == max_rda ? "%s (%i%%)" : "%s (%i-%i%%)";
1742 return string_format( format, v.first->name(), min_value, max_value );
1743 };
1744
1745 const auto max_nutr_vitamins = sorted_lex( max_nutr.vitamins );
1746 const std::string required_vits = enumerate_as_string(
1747 max_nutr_vitamins.begin(),
1748 max_nutr_vitamins.end(),
1749 [&]( const std::pair<vitamin_id, int> &v ) {
1750 return format_vitamin( v, true );
1751 } );
1752
1753 const std::string effect_vits = enumerate_as_string(
1754 max_nutr_vitamins.begin(),
1755 max_nutr_vitamins.end(),
1756 [&]( const std::pair<vitamin_id, int> &v ) {
1757 return format_vitamin( v, false );
1758 } );
1759
1760 if( !required_vits.empty() && parts->test( iteminfo_parts::FOOD_VITAMINS ) ) {
1761 info.emplace_back( "FOOD", _( "Vitamins (RDA): " ), required_vits );
1762 }
1763
1764 if( !effect_vits.empty() && parts->test( iteminfo_parts::FOOD_VIT_EFFECTS ) ) {
1765 info.emplace_back( "FOOD", _( "Other contents: " ), effect_vits );
1766 }
1767
1769
1770 if( you.allergy_type( *food_item ) != morale_type( "morale_null" ) ) {
1771 info.emplace_back( "DESCRIPTION",
1772 _( "* This food will cause an <bad>allergic reaction</bad>." ) );
1773 }
1774
1775 if( food_item->has_flag( flag_CANNIBALISM ) &&
1777 if( !you.has_trait_flag( trait_flag_CANNIBAL ) ) {
1778 info.emplace_back( "DESCRIPTION",
1779 _( "* This food contains <bad>human flesh</bad>." ) );
1780 } else {
1781 info.emplace_back( "DESCRIPTION",
1782 _( "* This food contains <good>human flesh</good>." ) );
1783 }
1784 }
1785
1786 if( food_item->is_tainted() && parts->test( iteminfo_parts::FOOD_CANNIBALISM ) ) {
1787 info.emplace_back( "DESCRIPTION",
1788 _( "* This food is <bad>tainted</bad> and will poison you." ) );
1789 }
1790
1791 ///\EFFECT_SURVIVAL >=3 allows detection of poisonous food
1792 if( food_item->has_flag( flag_HIDDEN_POISON ) && you.get_skill_level( skill_survival ) >= 3 &&
1793 parts->test( iteminfo_parts::FOOD_POISON ) ) {
1794 info.emplace_back( "DESCRIPTION",
1795 _( "* On closer inspection, this appears to be "
1796 "<bad>poisonous</bad>." ) );
1797 }
1798
1799 ///\EFFECT_SURVIVAL >=5 allows detection of hallucinogenic food
1800 if( food_item->has_flag( flag_HIDDEN_HALLU ) && you.get_skill_level( skill_survival ) >= 5 &&
1802 info.emplace_back( "DESCRIPTION",
1803 _( "* On closer inspection, this appears to be "
1804 "<neutral>hallucinogenic</neutral>." ) );
1805 }
1806
1807 if( food_item->goes_bad() && parts->test( iteminfo_parts::FOOD_ROT ) ) {
1808 const std::string rot_time = to_string_clipped( food_item->get_shelf_life() );
1809 info.emplace_back( "DESCRIPTION",
1810 string_format( _( "* This food is <neutral>perishable</neutral>, "
1811 "and at room temperature has an estimated nominal "
1812 "shelf life of <info>%s</info>." ), rot_time ) );
1813
1814
1815 if( parts->test( iteminfo_parts::FOOD_ROT_STORAGE ) ) {
1816 const char *temperature_description;
1817 bool print_freshness_duration = false;
1818 // There should be a better way to do this...
1819 switch( temperature ) {
1822 temperature_description = _( "* Current storage conditions <bad>do not</bad> "
1823 "protect this item from rot." );
1824 }
1825 break;
1828 temperature_description = _( "* Current storage conditions <neutral>partially</neutral> "
1829 "protect this item from rot. It will stay fresh at least <info>%s</info>." );
1830 print_freshness_duration = true;
1831 }
1832 break;
1834 temperature_description = _( "* Current storage conditions <good>fully</good> "
1835 "protect this item from rot. It will stay fresh indefinitely." );
1836 }
1837 break;
1838 default: {
1839 temperature_description = "BUGGED TEMPERATURE INFO";
1840 }
1841 }
1842
1843 if( print_freshness_duration ) {
1844 time_duration remaining_fresh = food_item->minimum_freshness_duration( temperature );
1845 std::string time_string = to_string_clipped( remaining_fresh );
1846 info.emplace_back( "DESCRIPTION", string_format( temperature_description, time_string ) );
1847 } else {
1848 info.emplace_back( "DESCRIPTION", temperature_description );
1849 }
1850 }
1851
1852 if( !food_item->rotten() ) {
1853 info.emplace_back( "DESCRIPTION", get_freshness_description( *food_item ) );
1854 }
1855
1856 if( food_item->has_flag( flag_NO_PARASITES ) ) {
1857 info.emplace_back( "DESCRIPTION",
1858 _( "* It seems that deep freezing <good>killed all "
1859 "parasites</good>." ) );
1860 }
1861 if( food_item->rotten() ) {
1862 if( you.has_bionic( bio_digestion ) ) {
1863 info.push_back( iteminfo( "DESCRIPTION",
1864 _( "This food has started to <neutral>rot</neutral>, "
1865 "but <info>your bionic digestion can tolerate "
1866 "it</info>." ) ) );
1867 } else if( you.has_trait( trait_SAPROVORE ) ) {
1868 info.push_back( iteminfo( "DESCRIPTION",
1869 _( "This food has started to <neutral>rot</neutral>, "
1870 "but <info>you can tolerate it</info>." ) ) );
1871 } else {
1872 info.push_back( iteminfo( "DESCRIPTION",
1873 _( "This food has started to <bad>rot</bad>. "
1874 "<info>Eating</info> it would be a <bad>very bad "
1875 "idea</bad>." ) ) );
1876 }
1877 }
1878 }
1879}
bool has_trait_flag(const std::string &b) const
Returns true if player has a trait with a flag.
Definition: mutation.cpp:106
virtual bool has_artifact_with(art_effect_passive effect) const
Definition: character.cpp:3204
nutrients compute_effective_nutrients(const item &) const
std::pair< nutrients, nutrients > compute_nutrient_range(const item &, const recipe_id &, const cata::flat_set< std::string > &extra_flags={}) const
Get calorie & vitamin contents for a comestible, taking into account character traits.
time_duration vitamin_rate(const vitamin_id &vit) const
Get vitamin usage rate (minutes per unit) accounting for bionics, mutations and effects.
std::pair< int, int > fun_for(const item &comest) const
Handles the enjoyability value for a comestible.
bool rotten() const
returns true if item is now rotten after all shelf life has elapsed
Definition: item.h:850
time_duration minimum_freshness_duration(temperature_flag temperature) const
Time that this item is guaranteed to stay fresh.
Definition: item.cpp:5700
const cata::value_ptr< islot_comestible > & get_comestible() const
Definition: item.cpp:10124
bool is_tainted() const
Is item derived from a zombie?
Definition: item.cpp:9817
bool is_item_on_loop(const itype_id &) const
@ AEP_SUPER_CLAIRVOYANCE
Definition: enums.h:112
static const std::string flag_HIDDEN_POISON("HIDDEN_POISON")
static const std::string flag_NO_DISPLAY("NO_DISPLAY")
static const bionic_id bio_digestion("bio_digestion")
static const trait_id trait_CARNIVORE("CARNIVORE")
static const std::string flag_CANNIBALISM("CANNIBALISM")
static const std::string flag_HIDDEN_HALLU("HIDDEN_HALLU")
static const trait_id trait_SAPROVORE("SAPROVORE")
static const std::string flag_NO_PARASITES("NO_PARASITES")
static const std::string trait_flag_CANNIBAL("CANNIBAL")
static const skill_id skill_survival("survival")
static std::string get_freshness_description(const item &food_item)
Definition: item.cpp:1111
constexpr T max_value()
recipe_dictionary recipe_dict
int kcal
amount of kcal this food has
Definition: stomach.h:18
std::map< vitamin_id, int > vitamins
vitamins potentially provided by this comestible (if any)
Definition: stomach.h:21
int get_vitamin(const vitamin_id &) const
Definition: stomach.cpp:42
string_id< recipe > recipe_id
Definition: type_id.h:143
@ VITAMIN
Definition: vitamin.h:19

References _, AEP_SUPER_CLAIRVOYANCE, Character::allergy_type(), bio_digestion, charges, Character::compute_effective_nutrients(), Character::compute_nutrient_range(), corpse, debug, enumerate_as_string(), flag_CANNIBALISM(), flag_HIDDEN_HALLU(), flag_HIDDEN_POISON(), flag_NO_DISPLAY(), flag_NO_PARASITES(), FOOD_CANNIBALISM, FOOD_HALLUCINOGENIC, FOOD_JOY, FOOD_NUTRITION, FOOD_POISON, FOOD_PORTIONS, FOOD_QUENCH, FOOD_ROT, FOOD_ROT_STORAGE, FOOD_SMELL, FOOD_VIT_EFFECTS, FOOD_VITAMINS, format(), Character::fun_for(), g, get_avatar(), get_comestible(), get_freshness_description(), get_shelf_life(), Character::get_skill_level(), get_var(), nutrients::get_vitamin(), goes_bad(), Character::has_artifact_with(), Character::has_bionic(), has_flag(), Character::has_trait(), Character::has_trait_flag(), info(), insert_separation_line(), recipe_dictionary::is_item_on_loop(), is_tainted(), nutrients::kcal, detail::max_value(), minimum_freshness_duration(), mtype::nname(), iteminfo::no_newline, recipe_dict, rotten(), skill_survival, sorted_lex(), sign::space, string_format(), TEMP_FREEZER, TEMP_FRIDGE, TEMP_HEATER, TEMP_NORMAL, TEMP_ROOT_CELLAR, iteminfo_query::test(), to_string_clipped(), trait_CARNIVORE, trait_flag_CANNIBAL(), trait_SAPROVORE, typeId(), VITAMIN, Character::vitamin_rate(), and nutrients::vitamins.

Referenced by info().

◆ fuel_energy()

float item::fuel_energy ( ) const

Returns energy of one charge of this item as fuel for an engine.

Definition at line 6816 of file item.cpp.

6817{
6818 return is_fuel() ? type->fuel->energy : 0.0f;
6819}
bool is_fuel() const
Definition: item.cpp:6760
cata::value_ptr< islot_fuel > fuel
Definition: itype.h:858

References itype::fuel, is_fuel(), and type.

Referenced by Character::burn_fuel(), vehicle_part::consume_energy(), vehicle::consume_fuel(), vehicle::consumption_per_hour(), Character::get_acquirable_energy(), game::on_move_effects(), and Character::passive_power_gen().

◆ fuel_pump_terrain()

std::string item::fuel_pump_terrain ( ) const

Returns the string of the id of the terrain that pumps this fuel, if any.

Definition at line 6821 of file item.cpp.

6822{
6823 return is_fuel() ? type->fuel->pump_terrain : "t_null";
6824}

References itype::fuel, is_fuel(), and type.

Referenced by map::place_gas_pump().

◆ get_available_recipes()

std::vector< std::pair< const recipe *, int > > item::get_available_recipes ( const player u) const

Enumerates recipes available from this book and the skill level required to use them.

Definition at line 7115 of file item.cpp.

7116{
7117 std::vector<std::pair<const recipe *, int>> recipe_entries;
7118 if( is_book() ) {
7119 for( const islot_book::recipe_with_description_t &elem : type->book->recipes ) {
7120 if( u.get_skill_level( elem.recipe->skill_used ) >= elem.skill_level ) {
7121 recipe_entries.push_back( std::make_pair( elem.recipe, elem.skill_level ) );
7122 }
7123 }
7124 } else if( has_var( "EIPC_RECIPES" ) ) {
7125 // See einkpc_download_memory_card() in iuse.cpp where this is set.
7126 const std::string recipes = get_var( "EIPC_RECIPES" );
7127 // Capture the index one past the delimiter, i.e. start of target string.
7128 size_t first_string_index = recipes.find_first_of( ',' ) + 1;
7129 while( first_string_index != std::string::npos ) {
7130 size_t next_string_index = recipes.find_first_of( ',', first_string_index );
7131 if( next_string_index == std::string::npos ) {
7132 break;
7133 }
7134 std::string new_recipe = recipes.substr( first_string_index,
7135 next_string_index - first_string_index );
7136 const recipe *r = &recipe_id( new_recipe ).obj();
7137 if( u.get_skill_level( r->skill_used ) >= r->difficulty ) {
7138 recipe_entries.push_back( std::make_pair( r, r->difficulty ) );
7139 }
7140 first_string_index = next_string_index + 1;
7141 }
7142 }
7143 return recipe_entries;
7144}
int difficulty
Definition: recipe.h:62

References itype::book, recipe::difficulty, Character::get_skill_level(), get_var(), has_var(), is_book(), string_id< T >::obj(), islot_book::recipe_with_description_t::recipe, islot_book::recipe_with_description_t::skill_level, recipe::skill_used, and type.

Referenced by npc::add_msg_player_or_say(), and avatar::do_read().

◆ get_base_env_resist_w_filter()

int item::get_base_env_resist_w_filter ( ) const

Returns the base resistance to environmental effects if an item (for example a gas mask) requires a gas filter to operate and this filter is installed.

Used in iuse::gasmask to change protection of a gas mask if it has (or don't has) filters. For other applications use get_env_resist() above.

Definition at line 5777 of file item.cpp.

5778{
5779 const islot_armor *t = find_armor_data();
5780 if( t == nullptr ) {
5781 return is_pet_armor() ? type->pet_armor->env_resist_w_filter : 0;
5782 }
5783 return t->env_resist_w_filter;
5784}
const islot_armor * find_armor_data() const
If this is an armor item, return its armor data.
Definition: item.cpp:6682
int env_resist_w_filter
Environmental protection of a gas mask with installed filter.
Definition: itype.h:267
cata::value_ptr< islot_pet_armor > pet_armor
Definition: itype.h:853

References islot_armor::env_resist_w_filter, find_armor_data(), is_pet_armor(), itype::pet_armor, and type.

Referenced by armor_protection_info(), iuse::dive_tank(), and iuse::gasmask().

◆ get_base_material()

const material_type & item::get_base_material ( ) const

Get the basic (main) material of this item.

May return the null-material.

Definition at line 7151 of file item.cpp.

7152{
7153 const std::vector<material_id> &mats = made_of();
7154 return mats.empty() ? material_id::NULL_ID().obj() : mats.front().obj();
7155}

References made_of(), string_id< material_type >::NULL_ID(), and string_id< T >::obj().

Referenced by Character::armor_absorb(), and durability_indicator().

◆ get_cable_target()

std::optional< tripoint > item::get_cable_target ( Character p,
const tripoint pos 
) const

Gets the point (vehicle tile) the cable is connected to.

Returns nothing if not connected to anything.

Definition at line 9342 of file item.cpp.

9343{
9344 const std::string &state = get_var( "state" );
9345 if( state != "pay_out_cable" && state != "cable_charger_link" ) {
9346 return std::nullopt;
9347 }
9348 map &here = get_map();
9349 const optional_vpart_position vp_pos = here.veh_at( pos );
9350 if( vp_pos ) {
9351 const std::optional<vpart_reference> seat = vp_pos.part_with_feature( "BOARDABLE", true );
9352 if( seat && p == seat->vehicle().get_passenger( seat->part_index() ) ) {
9353 return pos;
9354 }
9355 }
9356
9357 tripoint source( get_var( "source_x", 0 ), get_var( "source_y", 0 ), get_var( "source_z", 0 ) );
9358
9359 return here.getlocal( source );
9360}
Manage and cache data about a part of the map.
Definition: map.h:384
tripoint getlocal(const tripoint &p) const
Inverse of getabs.
Definition: map.cpp:8387
optional_vpart_position veh_at(const tripoint &p) const
Checks if tile is occupied by vehicle and by which part.
Definition: map.cpp:1073
Simple wrapper to forward functions that may return a std::optional to vpart_position.
std::optional< vpart_reference > part_with_feature(const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2482

References get_map(), get_var(), map::getlocal(), optional_vpart_position::part_with_feature(), and map::veh_at().

Referenced by process_cable().

◆ get_cached_tool_selections()

const std::vector< comp_selection< tool_comp > > & item::get_cached_tool_selections ( ) const

Definition at line 10118 of file item.cpp.

10119{
10120 assert( craft_data_ );
10121 return craft_data_->cached_tool_selections;
10122}

References craft_data_.

◆ get_category()

const item_category & item::get_category ( ) const

Definition at line 8691 of file item.cpp.

8692{
8693 if( is_container() && !contents.empty() ) {
8694 return contents.front().get_category();
8695 }
8696
8697 static item_category null_category;
8698 return type->category_force.is_valid() ? type->category_force.obj() : null_category;
8699}
Contains metadata for one category of items.
Definition: item_category.h:35
item_category_id category_force
If set via JSON forces item category to this (preventing automatic assignment)
Definition: itype.h:1003

References itype::category_force, contents, item_contents::empty(), item_contents::front(), get_category(), is_container(), string_id< T >::is_valid(), string_id< T >::obj(), and type.

Referenced by inventory_selector::add_items(), basic_info(), json_talk_topic::gen_responses(), get_category(), inventory_entry::get_category_ptr(), zone_manager::get_near_zone_type_for_item(), is_map(), map_item_stack::map_item_stack_sort(), operator<(), conditional_t< T >::set_has_item_category(), and spoilage_sort_order().

◆ get_chapters()

int item::get_chapters ( ) const

How many chapters the book has (if any).

Will be 0 if the item is not a book, or if it has no chapters at all. Each reading will "consume" a chapter, if the book has no unread chapters, it's less fun.

Definition at line 7089 of file item.cpp.

7090{
7091 if( !type->book ) {
7092 return 0;
7093 }
7094 return type->book->chapters;
7095}

References itype::book, and type.

Referenced by display_name(), character_funcs::get_book_fun_for(), get_remaining_chapters(), and io().

◆ get_clothing_mod_val()

float item::get_clothing_mod_val ( clothing_mod_type  type) const

Definition at line 10143 of file item.cpp.

10144{
10146 type );
10147 return get_var( key, 0.0 );
10148}
static const std::string CLOTHING_MOD_VAR_PREFIX("clothing_mod_")
std::string string_from_clothing_mod_type(clothing_mod_type type)

References CLOTHING_MOD_VAR_PREFIX(), get_var(), clothing_mods::string_from_clothing_mod_type(), and type.

Referenced by acid_resist(), bash_resist(), bullet_resist(), cut_resist(), fire_resist(), get_encumber_when_containing(), get_storage(), and get_warmth().

◆ get_comestible()

◆ get_comestible_fun()

int item::get_comestible_fun ( ) const

Definition at line 5482 of file item.cpp.

5483{
5484 if( !is_comestible() ) {
5485 return 0;
5486 }
5487 int fun = get_comestible()->fun;
5488 for( const std::string &flag : item_tags ) {
5489 fun += json_flag::get( flag ).taste_mod();
5490 }
5491 for( const std::string &flag : type->get_flags() ) {
5492 fun += json_flag::get( flag ).taste_mod();
5493 }
5494
5495 return fun;
5496}
bool is_comestible() const
Definition: item.cpp:6587
int taste_mod() const
The flag's modifier on the fun value of comestibles.
Definition: flag.h:55

References json_flag::get(), get_comestible(), itype::get_flags(), is_comestible(), item_tags, json_flag::taste_mod(), and type.

Referenced by iuse::blech(), basecamp::distribute_food(), mattack::eat_food(), Character::fun_for(), med_info(), rate_food(), and npc::will_accept_from_player().

◆ get_contained()

const item & item::get_contained ( ) const

Return a contained item (if any and only one).

Definition at line 7051 of file item.cpp.

7052{
7053 if( contents.empty() ) {
7054 return null_item_reference();
7055 }
7056 return contents.front();
7057}
item & null_item_reference()
Returns a reference to a null item (see item::is_null).
Definition: item.cpp:322

References contents, item_contents::empty(), item_contents::front(), and null_item_reference().

Referenced by Character::consume_effects(), basecamp::distribute_food(), trading_window::get_var_trade(), Character::invoke_item(), examine_item_menu::rate_action_use(), ranged::throw_item(), try_consume(), avatar_funcs::use_item(), avatar::wield(), avatar_action::wield(), npc::wield_better_weapon(), and npc::will_accept_from_player().

◆ get_container_capacity()

units::volume item::get_container_capacity ( ) const

It returns the total capacity (volume) of the container for liquids.

Definition at line 8401 of file item.cpp.

8402{
8403 if( !is_container() ) {
8404 return 0_ml;
8405 }
8406 return type->container->contains;
8407}

References itype::container, is_container(), and type.

Referenced by vehicle_part::ammo_capacity(), display_name(), get_remaining_capacity_for_liquid(), get_total_capacity(), is_funnel_container(), Item_factory::migrate_item(), Item_modifier::modify(), and ranged::throw_item().

◆ get_continue_reqs()

requirement_data item::get_continue_reqs ( ) const

Returns requirement data representing what is needed to resume work on an in progress craft.

Causes a debugmsg and returns empty requirement data if called on a non-craft

Returns
what is needed to continue craft, may be empty requirement data

Definition at line 975 of file crafting.cpp.

976{
977 if( !is_craft() ) {
978 debugmsg( "get_continue_reqs() called on non-craft '%s.' Aborting.", tname() );
979 return requirement_data();
980 }
982}
static requirement_data continue_requirements(const std::vector< item_comp > &required_comps, const std::list< item > &remaining_comps)
Returns the item requirements to continue an in progress craft with the passed components.

References components, requirement_data::continue_requirements(), craft_data_, debugmsg, is_craft(), and tname().

◆ get_corpse_name()

std::string item::get_corpse_name ( )

Returns name of deceased being if it had any or empty string if not.

Definition at line 9914 of file item.cpp.

9915{
9916 if( corpse_name.empty() ) {
9917 return std::string();
9918 }
9919 return corpse_name;
9920}
std::string corpse_name
Definition: item.h:2177

References corpse_name.

◆ get_coverage()

int item::get_coverage ( ) const

Returns the relative coverage that this item has when worn.

Values range from 0 (not covering anything, or no armor at all) to 100 (covering the whole body part). Items that cover more are more likely to absorb damage from attacks.

Definition at line 5900 of file item.cpp.

5901{
5902 const islot_armor *t = find_armor_data();
5903 if( t == nullptr ) {
5904 return 0;
5905 }
5906 return t->coverage;
5907}
int coverage
Percentage of the body part area that this item covers.
Definition: itype.h:255

References islot_armor::coverage, and find_armor_data().

Referenced by Character::armor_absorb(), armor_info(), armor_inventory_preset::armor_inventory_preset(), Character::block_ranged_hit(), relic_funcs::check_recharge_reqs(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), clothing_mod::get_mod_val(), character_funcs::is_bp_immune_to(), map::player_in_field(), tutorial_game::post_action(), wind_resistance_from_item_list(), and mdefense::zapback().

◆ get_covered_body_parts() [1/2]

body_part_set item::get_covered_body_parts ( ) const

Bitset of all covered body parts.

If the bit is set, the body part is covered by this item (when worn). The index of the bit should be a body part, for example:

if( some_armor.get_covered_body_parts().test( bp_head ) ) { ... }

For testing only a single body part, use covers instead. This function allows you to get the whole covering data in one call.

Definition at line 753 of file item.cpp.

754{
756}

References get_covered_body_parts(), and get_side().

Referenced by npc::adjust_worn(), Character::armor_absorb(), armor_info(), Character::can_swap(), Character::can_wear(), covers(), get_covered_body_parts(), layer_item(), on_wear(), player_morale::on_worn_item_washed(), player_morale::set_worn(), and weather_effect::wet_player().

◆ get_covered_body_parts() [2/2]

body_part_set item::get_covered_body_parts ( side  s) const

Bitset of all covered body parts, from a specific side.

If the bit is set, the body part is covered by this item (when worn). The index of the bit should be a body part, for example:

if( some_armor.get_covered_body_parts().test( bp_head ) ) { ... }

For testing only a single body part, use covers instead. This function allows you to get the whole covering data in one call.

Parameters
sSpecifies the side. Will be ignored for non-sided items.

Definition at line 758 of file item.cpp.

759{
760 body_part_set res;
761
762 if( is_gun() ) {
763 // Currently only used for guns with the should strap mod, other guns might
764 // go on another bodypart.
765 res.set( bp_torso );
766 }
767
768 const islot_armor *armor = find_armor_data();
769 if( armor == nullptr ) {
770 return res;
771 }
772
773 res |= armor->covers;
774
775 if( !armor->sided ) {
776 return res; // Just ignore the side.
777 }
778
779 switch( s ) {
780 case side::BOTH:
781 case side::num_sides:
782 break;
783
784 case side::LEFT:
785 res.reset( bp_arm_r );
786 res.reset( bp_hand_r );
787 res.reset( bp_leg_r );
788 res.reset( bp_foot_r );
789 break;
790
791 case side::RIGHT:
792 res.reset( bp_arm_l );
793 res.reset( bp_hand_l );
794 res.reset( bp_leg_l );
795 res.reset( bp_foot_l );
796 break;
797 }
798
799 return res;
800}
void set(const body_part &bp)
Definition: bodypart.h:242
void reset(const body_part &bp)
Definition: bodypart.h:245
bool sided
Whether this item can be worn on either side of the body.
Definition: itype.h:242
body_part_set covers
Bitfield of enum body_part TODO: document me.
Definition: itype.h:238

References BOTH, bp_arm_l, bp_arm_r, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_leg_l, bp_leg_r, bp_torso, islot_armor::covers, find_armor_data(), is_gun(), LEFT, num_sides, body_part_set::reset(), RIGHT, body_part_set::set(), and islot_armor::sided.

◆ get_enchantments()

const std::vector< enchantment > & item::get_enchantments ( ) const

Definition at line 6978 of file item.cpp.

6979{
6980 if( !is_relic() ) {
6981 static const std::vector<enchantment> fallback;
6982 return fallback;
6983 }
6984 return relic_data->get_enchantments();
6985}
bool is_relic() const
Definition: item.cpp:6973

References is_relic(), and relic_data.

Referenced by bonus_from_enchantments(), bonus_from_enchantments_wielded(), process_relic(), and Character::recalculate_enchantment_cache().

◆ get_encumber()

int item::get_encumber ( const Character p) const

Returns the encumbrance value that this item has when worn by given player.

Returns 0 if this is can not be worn at all.

Definition at line 5792 of file item.cpp.

5793{
5794
5795 units::volume contents_volume( 0_ml );
5796
5797 contents_volume += contents.item_size_modifier();
5798
5799 if( p.is_worn( *this ) ) {
5800 const islot_armor *t = find_armor_data();
5801
5802 if( t != nullptr && t->max_encumber != 0 ) {
5803 units::volume char_storage( 0_ml );
5804
5805 for( const item &e : p.worn ) {
5806 char_storage += e.get_storage();
5807 }
5808
5809 if( char_storage != 0_ml ) {
5810 // Cast up to 64 to prevent overflow. Dividing before would prevent this but lose data.
5811 contents_volume += units::from_milliliter( static_cast<int64_t>( t->storage.value() ) *
5812 p.inv.volume().value() / char_storage.value() );
5813 }
5814 }
5815 }
5816
5817 return get_encumber_when_containing( p, contents_volume );
5818}
inventory inv
Definition: character.h:1576
std::list< item > worn
Definition: character.h:1564
bool is_worn(const item &thing) const
Definition: character.h:1099
units::volume volume() const
Definition: inventory.cpp:1060
units::volume item_size_modifier() const
constexpr quantity< value_type, volume_in_milliliter_tag > from_milliliter(const value_type v)
Definition: units_volume.h:25
int max_encumber
When storage is full, how much it encumbers the player.
Definition: itype.h:250
units::volume storage
How much storage this items provides when worn.
Definition: itype.h:275

References contents, find_armor_data(), units::from_milliliter(), get_encumber_when_containing(), get_storage(), Character::inv, Character::is_worn(), item_contents::item_size_modifier(), islot_armor::max_encumber, islot_armor::storage, units::quantity< V, U >::value(), inventory::volume(), and Character::worn.

Referenced by armor_fit_info(), armor_info(), armor_inventory_preset::armor_inventory_preset(), repair_item_actor::can_repair_target(), Character::can_wear(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), repair_item_actor::default_action(), Character::head_cloth_encumbrance(), Character::item_wear_cost(), layer_item(), tname(), and sew_advanced_actor::use().

◆ get_encumber_when_containing()

int item::get_encumber_when_containing ( const Character p,
const units::volume contents_volume 
) const

Returns the encumbrance value that this item has when worn by given player, when containing a particular volume of contents.

Returns 0 if this can not be worn at all.

Definition at line 5820 of file item.cpp.

5822{
5823 const islot_armor *t = find_armor_data();
5824 if( t == nullptr ) {
5825 // handle wearable guns (e.g. shoulder strap) as special case
5826 return is_gun() ? volume() / 750_ml : 0;
5827 }
5828 int encumber = t->encumber;
5829
5830 // Non-rigid items add additional encumbrance proportional to their volume
5831 if( !type->rigid ) {
5832 const int capacity = get_total_capacity().value();
5833
5834 if( t->max_encumber != 0 ) {
5835
5836 if( capacity > 0 ) {
5837 // Cast up to 64 to prevent overflow. Dividing before would prevent this but lose data.
5838 encumber += static_cast<int64_t>( t->max_encumber - t->encumber ) * contents_volume.value() /
5839 capacity;
5840 } else {
5841 debugmsg( "Non-rigid item (%s) without storage capacity.", tname() );
5842 }
5843 } else {
5844 encumber += contents_volume / 500_ml;
5845 }
5846 }
5847
5848 // Fit checked before changes, fitting shouldn't reduce penalties from patching.
5849 if( has_flag( flag_FIT ) && has_flag( flag_VARSIZE ) ) {
5850 encumber = std::max( encumber / 2, encumber - 10 );
5851 }
5852
5853 // TODO: Should probably have sizing affect coverage
5854 const sizing sizing_level = get_sizing( p, encumber != 0 );
5855 switch( sizing_level ) {
5858 // non small characters have a HARD time wearing undersized clothing
5859 encumber *= 3;
5860 break;
5863 // clothes bag up around smol characters and encumber them more
5864 encumber *= 2;
5865 break;
5866 default:
5867 break;
5868 }
5869
5870 encumber += static_cast<int>( std::ceil( get_clothing_mod_val( clothing_mod_type_encumbrance ) ) );
5871
5872 return encumber;
5873}
@ clothing_mod_type_encumbrance
Definition: clothing_mod.h:22
int encumber
How much this item encumbers the player.
Definition: itype.h:246

References big_sized_small_char, clothing_mod_type_encumbrance, debugmsg, islot_armor::encumber, find_armor_data(), flag_FIT(), flag_VARSIZE(), get_clothing_mod_val(), get_sizing(), get_total_capacity(), has_flag(), human_sized_small_char, is_gun(), islot_armor::max_encumber, itype::rigid, small_sized_big_char, small_sized_human_char, tname(), type, units::quantity< V, U >::value(), and volume().

Referenced by armor_info(), and get_encumber().

◆ get_env_resist()

int item::get_env_resist ( int  override_base_resist = 0) const

Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides when worn.

See player::get_env_resist. Higher values are better. For non-armor it returns 0.

Parameters
override_base_resistPass this to artifically increase the base resistance, so that the function can take care of other modifications to resistance for you. Note that this parameter will never decrease base resistnace.

Definition at line 5763 of file item.cpp.

5764{
5765 const islot_armor *t = find_armor_data();
5766 if( t == nullptr ) {
5767 return is_pet_armor() ? type->pet_armor->env_resist : 0;
5768 }
5769 // modify if item is a gas mask and has filter
5770 int resist_base = t->env_resist;
5771 int resist_filter = get_var( "overwrite_env_resist", 0 );
5772 int resist = std::max( { resist_base, resist_filter, override_base_resist } );
5773
5774 return std::lround( resist * get_relative_health() );
5775}
float get_relative_health() const
Relative item health.
Definition: item.cpp:6221
int env_resist
Resistance to environmental effects.
Definition: itype.h:263

References islot_armor::env_resist, find_armor_data(), get_relative_health(), get_var(), is_pet_armor(), itype::pet_armor, and type.

Referenced by acid_resist(), armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), fire_resist(), and tutorial_game::post_action().

◆ get_explosion_data()

struct fuel_explosion item::get_explosion_data ( )

Definition at line 6831 of file item.cpp.

6832{
6833 static struct fuel_explosion null_data;
6834 return has_explosion_data() ? type->fuel->explosion_data : null_data;
6835}
bool has_explosion_data() const
Definition: item.cpp:6826

References type.

Referenced by vehicle::explode_fuel().

◆ get_flags()

const item::FlagsSetType & item::get_flags ( ) const

returs read-only set of flags of this item (not including flags from item type or gunmods)

Definition at line 5353 of file item.cpp.

5354{
5355 return item_tags;
5356}

References item_tags.

Referenced by final_info().

◆ get_food() [1/2]

item * item::get_food ( )

Definition at line 6642 of file item.cpp.

6643{
6644 return get_food_impl( this );
6645}
static Item * get_food_impl(Item *it)
Definition: item.cpp:6631

References get_food_impl().

Referenced by basic_info(), color_in_inventory(), npc::consume_food(), npc::decide_needs(), zone_manager::get_near_zone_type_for_item(), and info().

◆ get_food() [2/2]

const item * item::get_food ( ) const

Definition at line 6647 of file item.cpp.

6648{
6649 return get_food_impl( this );
6650}

References get_food_impl().

◆ get_free_mod_locations()

int item::get_free_mod_locations ( const gunmod_location location) const

Number of mods that can still be installed into the given mod location, for non-guns it always returns 0.

Definition at line 4095 of file item.cpp.

4096{
4097 if( !is_gun() ) {
4098 return 0;
4099 }
4100
4101 std::map<gunmod_location, int> mod_locations = get_mod_locations();
4102
4103 const auto loc = mod_locations.find( location );
4104 if( loc == mod_locations.end() ) {
4105 return 0;
4106 }
4107 int result = loc->second;
4108 for( const item *elem : contents.all_items_top() ) {
4109 const cata::value_ptr<islot_gunmod> &mod = elem->type->gunmod;
4110 if( mod && mod->location == location ) {
4111 result--;
4112 }
4113 }
4114 return result;
4115}
This class is essentially a copyable unique pointer.
Definition: value_ptr.h:19
std::map< gunmod_location, int > get_mod_locations() const
Get mod locations, including those added by other mods.
Definition: item.cpp:4078

References item_contents::all_items_top(), contents, get_mod_locations(), and is_gun().

Referenced by saw_stock_actor::can_use_on(), gun_info(), avatar_funcs::gunmod_remove(), and is_gunmod_compatible().

◆ get_gun_ups_drain()

int item::get_gun_ups_drain ( ) const

Definition at line 9932 of file item.cpp.

9933{
9934 int draincount = 0;
9935 if( type->gun ) {
9936 int modifier = 0;
9937 float multiplier = 1.0f;
9938 for( const item *mod : gunmods() ) {
9939 modifier += mod->type->gunmod->ups_charges_modifier;
9940 multiplier *= mod->type->gunmod->ups_charges_multiplier;
9941 }
9942 draincount = ( type->gun->ups_charges * multiplier ) + modifier;
9943 }
9944 return draincount;
9945}

References itype::gun, gunmods(), and type.

Referenced by character_funcs::ammo_count_for(), npc::decide_needs(), ranged::fire_gun(), ranged::gunmode_checks_weapon(), turret_data::query(), item_funcs::shots_remaining(), and target_ui::update_ammo_range_from_gun_mode().

◆ get_layer()

layer_level item::get_layer ( ) const

Returns clothing layer for item.

Definition at line 5875 of file item.cpp.

5876{
5877 if( type->armor ) {
5878 // We assume that an item will never have per-item flags defining its
5879 // layer, so we can defer to the itype.
5880 return type->layer;
5881 }
5882
5883 if( has_flag( flag_PERSONAL ) ) {
5884 return PERSONAL_LAYER;
5885 } else if( has_flag( flag_SKINTIGHT ) ) {
5886 return UNDERWEAR_LAYER;
5887 } else if( has_flag( flag_WAIST ) ) {
5888 return WAIST_LAYER;
5889 } else if( has_flag( flag_OUTER ) ) {
5890 return OUTER_LAYER;
5891 } else if( has_flag( flag_BELTED ) ) {
5892 return BELTED_LAYER;
5893 } else if( has_flag( flag_AURA ) ) {
5894 return AURA_LAYER;
5895 } else {
5896 return REGULAR_LAYER;
5897 }
5898}
@ WAIST_LAYER
Definition: enums.h:222
@ UNDERWEAR_LAYER
Definition: enums.h:218
@ REGULAR_LAYER
Definition: enums.h:220
@ BELTED_LAYER
Definition: enums.h:226
@ PERSONAL_LAYER
Definition: enums.h:216
@ AURA_LAYER
Definition: enums.h:228
@ OUTER_LAYER
Definition: enums.h:224
layer_level layer
Definition: itype.h:1028

References itype::armor, AURA_LAYER, BELTED_LAYER, flag_AURA(), flag_BELTED(), flag_OUTER(), flag_PERSONAL(), flag_SKINTIGHT(), flag_WAIST(), has_flag(), itype::layer, OUTER_LAYER, PERSONAL_LAYER, REGULAR_LAYER, type, UNDERWEAR_LAYER, and WAIST_LAYER.

Referenced by Character::item_wear_cost(), profession::items(), and layer_item().

◆ get_making()

const recipe & item::get_making ( ) const

Get the stored recipe for in progress crafts.

Causes a debugmsg if called on a non-craft and returns the null recipe.

Returns
the recipe in progress

Definition at line 10089 of file item.cpp.

10090{
10091 if( !craft_data_ ) {
10092 debugmsg( "'%s' is not a craft or has a null recipe", tname() );
10093 static const recipe dummy{};
10094 return dummy;
10095 }
10096 assert( craft_data_->making );
10097 return *craft_data_->making;
10098}

References craft_data_, debugmsg, and tname().

Referenced by iuse::craft(), handle_craft_failure(), and set_next_failure_point().

◆ get_min_str()

int item::get_min_str ( ) const

Definition at line 10044 of file item.cpp.

10045{
10046 if( type->gun ) {
10047 int min_str = type->min_str;
10048 for( const item *mod : gunmods() ) {
10049 min_str += mod->type->gunmod->min_str_required_mod;
10050 }
10051 return min_str > 0 ? min_str : 0;
10052 } else {
10053 return type->min_str;
10054 }
10055}
int min_str
Definition: itype.h:937

References itype::gun, gunmods(), itype::min_str, and type.

Referenced by basic_info(), Character::enumerate_unmet_requirements(), ranged::get_str_draw_penalty(), aim_activity_actor::load_RAS_weapon(), Character::meets_stat_requirements(), ranged::str_draw_damage_modifier(), ranged::str_draw_dispersion_modifier(), and ranged::str_draw_range_modifier().

◆ get_mod_locations()

std::map< gunmod_location, int > item::get_mod_locations ( ) const

Get mod locations, including those added by other mods.

Definition at line 4078 of file item.cpp.

4079{
4080 std::map<gunmod_location, int> mod_locations = type->gun->valid_mod_locations;
4081
4082 for( const item *mod : gunmods() ) {
4083 if( !mod->type->gunmod->add_mod.empty() ) {
4084 std::map<gunmod_location, int> add_locations = mod->type->gunmod->add_mod;
4085
4086 for( const std::pair<const gunmod_location, int> &add_location : add_locations ) {
4087 mod_locations[add_location.first] += add_location.second;
4088 }
4089 }
4090 }
4091
4092 return mod_locations;
4093}

References itype::gun, gunmods(), and type.

Referenced by get_free_mod_locations(), gun_info(), avatar_funcs::gunmod_remove(), and is_gunmod_compatible().

◆ get_mtype()

const mtype * item::get_mtype ( ) const
Returns
The monster type associated with this item (corpse). It is usually the type that this item is made of (e.g. corpse, meat or blood of the monster). May return a null-pointer.

Definition at line 6625 of file item.cpp.

6626{
6627 return corpse;
6628}

References corpse.

Referenced by computer_session::action_blood_anal(), burn(), activity_handlers::butcher_finish(), butcher_time_to_cut(), butchery_drops_harvest(), butchery_quarter(), consider_butchery(), editmap::draw_main_ui_overlay(), and game::revive_corpse().

◆ get_next_failure_point()

int item::get_next_failure_point ( ) const

Get the failure point stored in this item.

returns INT_MAX if the failure point is unset. Causes a debugmsg and returns INT_MAX if called on a non-craft.

Returns
an integer >= 0 representing a percent to 5 decimal places. 67.32 percent would be represented as 6732000

Definition at line 895 of file crafting.cpp.

896{
897 if( !is_craft() ) {
898 debugmsg( "get_next_failure_point() called on non-craft '%s.' Aborting.", tname() );
899 return INT_MAX;
900 }
901 return craft_data_->next_failure_point >= 0 ? craft_data_->next_failure_point : INT_MAX;
902}

References craft_data_, debugmsg, is_craft(), and tname().

◆ get_old_owner()

faction_id item::get_old_owner ( ) const

Definition at line 1285 of file item.cpp.

1286{
1288 return old_owner;
1289}
faction_id old_owner
Definition: item.h:2235
void validate_ownership() const
Definition: item.cpp:1291

References old_owner, and validate_ownership().

Referenced by is_old_owner().

◆ get_owner()

faction_id item::get_owner ( ) const

Definition at line 1279 of file item.cpp.

1280{
1282 return owner;
1283}

References owner, and validate_ownership().

Referenced by get_owner_name(), handle_pickup_ownership(), is_owned_by(), and query_consume_ownership().

◆ get_owner_name()

std::string item::get_owner_name ( ) const

Definition at line 1261 of file item.cpp.

1262{
1263 if( !g->faction_manager_ptr->get( get_owner() ) ) {
1264 debugmsg( "item::get_owner_name() item %s has no valid nor null faction id ", tname() );
1265 return "no owner";
1266 }
1267 return g->faction_manager_ptr->get( get_owner() )->name;
1268}
faction_id get_owner() const
Definition: item.cpp:1279

References debugmsg, g, get_owner(), and tname().

Referenced by basic_info().

◆ get_pet_armor_bodytype()

std::string item::get_pet_armor_bodytype ( ) const

Definition at line 5941 of file item.cpp.

5942{
5943 return is_pet_armor() ? type->pet_armor->bodytype : "";
5944}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_pet_armor_max_vol()

units::volume item::get_pet_armor_max_vol ( ) const

Definition at line 5931 of file item.cpp.

5932{
5933 return is_pet_armor() ? type->pet_armor->max_vol : 0_ml;
5934}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_pet_armor_min_vol()

units::volume item::get_pet_armor_min_vol ( ) const

Definition at line 5936 of file item.cpp.

5937{
5938 return is_pet_armor() ? type->pet_armor->min_vol : 0_ml;
5939}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_plant_epoch()

time_duration item::get_plant_epoch ( ) const

Time it takes to grow from one stage to another.

There are 4 plant stages: seed, seedling, mature and harvest. Non-seed items return 0.

Definition at line 9779 of file item.cpp.

9780{
9781 if( !type->seed ) {
9782 return 0_turns;
9783 }
9784 // Growing times have been based around real world season length rather than
9785 // the default in-game season length to give
9786 // more accuracy for longer season lengths
9787 // Also note that seed->grow is the time it takes from seeding to harvest, this is
9788 // divided by 3 to get the time it takes from one plant state to the next.
9789 // TODO: move this into the islot_seed
9790 return type->seed->grow * calendar::season_ratio() / 3;
9791}
float season_ratio()
Definition: calendar.cpp:485
cata::value_ptr< islot_seed > seed
Definition: itype.h:865

References calendar::season_ratio(), itype::seed, and type.

◆ get_plant_name()

std::string item::get_plant_name ( ) const

The name of the plant as it appears in the various informational menus.

This should be translated. Returns an empty string for non-seed items.

Definition at line 9793 of file item.cpp.

9794{
9795 if( !type->seed ) {
9796 return std::string{};
9797 }
9798 return type->seed->plant_name.translated();
9799}

References itype::seed, and type.

Referenced by map::rotten_item_spawn().

◆ get_property_int64_t()

int64_t item::get_property_int64_t ( const std::string &  prop,
int64_t  def = 0 
) const

Definition at line 5369 of file item.cpp.

5370{
5371 const auto it = type->properties.find( prop );
5372 if( it != type->properties.end() ) {
5373 char *e = nullptr;
5374 int64_t r = std::strtoll( it->second.c_str(), &e, 10 );
5375 if( !it->second.empty() && *e == '\0' ) {
5376 return r;
5377 }
5378 debugmsg( "invalid property '%s' for item '%s'", prop.c_str(), tname() );
5379 }
5380 return def;
5381}
std::map< std::string, std::string > properties
Definition: itype.h:915

References debugmsg, itype::properties, tname(), and type.

Referenced by ranged::throw_item().

◆ get_property_string()

std::string item::get_property_string ( const std::string &  prop,
const std::string &  def = "" 
) const

Get typed property for item.

Return same type as the passed default value, or string where no default provided

Definition at line 5363 of file item.cpp.

5364{
5365 const auto it = type->properties.find( prop );
5366 return it != type->properties.end() ? it->second : def;
5367}

References itype::properties, and type.

Referenced by iuse::capture_monster_act().

◆ get_qualities()

std::map< quality_id, int > item::get_qualities ( ) const

Definition at line 5430 of file item.cpp.

5431{
5432 std::map<quality_id, int> qualities;
5433 for( const auto &quality : type->qualities ) {
5434 qualities[quality.first] = get_quality( quality.first );
5435 }
5436 return qualities;
5437}
int get_quality(const quality_id &id) const
Definition: item.cpp:5383
std::map< quality_id, int > qualities
Definition: itype.h:914

References get_quality(), itype::qualities, and type.

Referenced by inventory::update_quality_cache().

◆ get_quality()

int item::get_quality ( const quality_id id) const

EXCEPTION: Items with quality BOIL only count as such if they are empty, excluding items of their ammo type if they are tools.

Definition at line 5383 of file item.cpp.

5384{
5385 int return_quality = INT_MIN;
5386
5387 /**
5388 * EXCEPTION: Items with quality BOIL only count as such if they are empty,
5389 * excluding items of their ammo type if they are tools.
5390 */
5391 auto block_boil_filter = [this]( const item & itm ) {
5392 // We want to skip (do not block) only those : correct ammo, correct magazine, correct toolmod.Everything else should block.
5393 if( &itm == this ) {
5394 // Do not block if checking itself - we are checking only item contents not item itself.
5395 return false;
5396 } else if( itm.is_ammo() ) {
5397 return ammo_types().count( itm.ammo_type() ) == 0;
5398 } else if( itm.is_magazine() ) {
5399 // we want to return "fine for boiling" if any of the ammo types match and "blocks boiling" if none match.
5400 for( const ammotype &at : ammo_types() ) {
5401 for( const ammotype &mag_at : itm.ammo_types() ) {
5402 if( at == mag_at ) {
5403 return false;
5404 }
5405 }
5406 }
5407 return true;
5408 } else if( itm.is_toolmod() ) {
5409 return false;
5410 }
5411 return true;
5412 };
5413 // if it's has boil quality and it's empty, it's good to boil. If it's not empty and it's not a tool (it's probably a container), it's not good to boil. If it's a tool, it gets an extra chance: if it's only contents are mods or batteries, it's still good.
5414 // Also we are using inverted filter, since we don't care about items that the filter likes, we only care if it find something it doesn't like.
5415 if( id == quality_id( "BOIL" ) && !contents.empty() &&
5416 ( !is_tool() || has_item_with( block_boil_filter ) ) ) {
5417 return INT_MIN;
5418 }
5419
5420 for( const std::pair<const quality_id, int> &quality : type->qualities ) {
5421 if( quality.first == id ) {
5422 return_quality = quality.second;
5423 }
5424 }
5425 return_quality = std::max( return_quality, contents.best_quality( id ) );
5426
5427 return return_quality;
5428}
int best_quality(const quality_id &id) const
string_id< quality > quality_id
Definition: type_id.h:184

References ammo_types(), item_contents::best_quality(), contents, item_contents::empty(), visitable< item >::has_item_with(), is_tool(), itype::qualities, and type.

Referenced by iuse::clear_rubble(), iuse::crowbar(), dig_pit_moves_and_byproducts(), get_qualities(), bionic::get_quality(), has_quality_internal(), Character::item_with_best_of_quality(), activity_handlers::lockpicking_finish(), max_quality_internal(), and pick_lock_actor::use().

◆ get_random_material()

const material_type & item::get_random_material ( ) const

Get a material reference to a random material that this item is made of.

This might return the null-material, you may check this with material_type::ident. Note that this may also return a different material each time it's invoked (if the item is made from several materials).

Definition at line 7146 of file item.cpp.

7147{
7148 return random_entry( made_of(), material_id::NULL_ID() ).obj();
7149}
V random_entry(const C &container, D default_value)
Returns a random entry in the container.
Definition: rng.h:88

References made_of(), string_id< material_type >::NULL_ID(), and random_entry().

Referenced by Character::armor_absorb().

◆ get_relative_health()

float item::get_relative_health ( ) const

Relative item health.

Returns 1 for undamaged ||items, values in the range (0, 1) for damaged items and values above 1 for reinforced ++items.

Definition at line 6221 of file item.cpp.

6222{
6223 return ( max_damage() + 1.0f - damage() ) / ( max_damage() + 1.0f );
6224}

References damage(), and max_damage().

Referenced by get_base_env_resist(), and get_env_resist().

◆ get_relative_rot()

double item::get_relative_rot ( ) const

Get rot value relative to shelf life (or 0 if item does not spoil)

Definition at line 5531 of file item.cpp.

5532{
5533 if( goes_bad() ) {
5534 return rot / get_shelf_life();
5535 }
5536 return 0;
5537}
Definition: rot.cpp:11

References get_shelf_life(), and goes_bad().

Referenced by calc_rot(), Character::consume_effects(), fill_with(), Character::fun_for(), comestible_inventory_preset::get_freshness(), get_freshness_description(), get_most_rotten_component(), comestible_inventory_preset::get_time_left(), has_rotten_away(), item(), and rate_food().

◆ get_relic_recharge_scheme()

const std::vector< relic_recharge > & item::get_relic_recharge_scheme ( ) const

Definition at line 7025 of file item.cpp.

7026{
7027 return relic_data->get_recharge_scheme();
7028}

References relic_data.

Referenced by relic_funcs::process_recharge().

◆ get_reload_time()

int item::get_reload_time ( ) const

Returns the reload time of the gun.

Returns 0 if not a gun.

Definition at line 6528 of file item.cpp.

6529{
6530 if( !is_gun() && !is_magazine() ) {
6531 return 0;
6532 }
6533
6534 int reload_time = is_gun() ? type->gun->reload_time : type->magazine->reload_time;
6535 for( const item *mod : gunmods() ) {
6536 reload_time = static_cast<int>( reload_time * ( 100 + mod->type->gunmod->reload_modifier ) / 100 );
6537 }
6538
6539 return reload_time;
6540}

References itype::gun, gunmods(), is_gun(), is_magazine(), itype::magazine, and type.

Referenced by ideal_ranged_dps(), Character::item_reload_cost(), and item_reload_option::moves().

◆ get_remaining_capacity_for_liquid() [1/2]

int item::get_remaining_capacity_for_liquid ( const item liquid,
bool  allow_bucket = false,
std::string *  err = nullptr 
) const

How much more of this liquid (in charges) can be put in this container.

If this is not a container (or not suitable for the liquid), it returns 0. Note that mixing different types of liquid is not possible. Also note that this works for guns and tools that accept liquid ammo.

Parameters
liquidLiquid to check capacity for
allow_bucketAllow filling non-sealable containers
errMessage to print if no more material will fit

Definition at line 8430 of file item.cpp.

8432{
8433 const auto error = [ &err ]( const std::string & message ) {
8434 if( err != nullptr ) {
8435 *err = message;
8436 }
8437 return 0;
8438 };
8439
8440 int remaining_capacity = 0;
8441
8442 // TODO: (sm) is_reloadable_with and this function call each other and can recurse for
8443 // watertight containers.
8444 if( !is_container() && is_reloadable_with( liquid.typeId() ) ) {
8445 if( ammo_remaining() != 0 && ammo_current() != liquid.typeId() ) {
8446 return error( string_format( _( "You can't mix loads in your %s." ), tname() ) );
8447 }
8448 remaining_capacity = ammo_capacity() - ammo_remaining();
8449 } else if( is_container() ) {
8450 if( !type->container->watertight ) {
8451 return error( string_format( _( "That %s isn't water-tight." ), tname() ) );
8452 } else if( !type->container->seals && ( !allow_bucket || !is_bucket() ) ) {
8453 return error( string_format( is_bucket() ?
8454 _( "That %s must be on the ground or held to hold contents!" )
8455 : _( "You can't seal that %s!" ), tname() ) );
8456 } else if( !contents.empty() && contents.front().typeId() != liquid.typeId() ) {
8457 return error( string_format( _( "You can't mix loads in your %s." ), tname() ) );
8458 }
8459 remaining_capacity = liquid.charges_per_volume( get_container_capacity() );
8460 if( !contents.empty() ) {
8461 remaining_capacity -= contents.front().charges;
8462 }
8463 } else {
8464 return error( string_format( _( "That %1$s won't hold %2$s." ), tname(),
8465 liquid.tname() ) );
8466 }
8467
8468 if( remaining_capacity <= 0 ) {
8469 return error( string_format( _( "Your %1$s can't hold any more %2$s." ), tname(),
8470 liquid.tname() ) );
8471 }
8472
8473 return remaining_capacity;
8474}
std::string message
Definition: mapgen.cpp:411

References _, ammo_capacity(), ammo_current(), ammo_remaining(), charges, charges_per_volume(), itype::container, contents, item_contents::empty(), detail::digits::error, item_contents::front(), get_container_capacity(), is_bucket(), is_container(), is_reloadable_with(), mapgen_defer::message, string_format(), tname(), type, and typeId().

Referenced by add_rain_to_container(), fill_with(), get_remaining_capacity_for_liquid(), is_container_full(), maple_tree_sap_container(), advanced_inventory::move_content(), Character::pour_into(), item_reload_option::qty(), and reload().

◆ get_remaining_capacity_for_liquid() [2/2]

int item::get_remaining_capacity_for_liquid ( const item liquid,
const Character p,
std::string *  err = nullptr 
) const

Definition at line 8476 of file item.cpp.

8478{
8479 const bool allow_bucket = p.is_wielding( *this ) || !p.has_item( *this );
8480 int res = get_remaining_capacity_for_liquid( liquid, allow_bucket, err );
8481
8482 if( res > 0 && !type->rigid && p.inv.has_item( *this ) ) {
8483 const units::volume volume_to_expand = std::max( p.volume_capacity() - p.volume_carried(),
8484 0_ml );
8485
8486 res = std::min( liquid.charges_per_volume( volume_to_expand ), res );
8487
8488 if( res == 0 && err != nullptr ) {
8489 *err = string_format( _( "That %s doesn't have room to expand." ), tname() );
8490 }
8491 }
8492
8493 return res;
8494}
units::volume volume_capacity() const
Definition: character.cpp:2662
bool is_wielding(const item &target) const
Definition: character.cpp:3219
units::volume volume_carried() const
Definition: character.cpp:2535

References _, charges_per_volume(), get_remaining_capacity_for_liquid(), visitable< T >::has_item(), Character::inv, Character::is_wielding(), itype::rigid, string_format(), tname(), type, Character::volume_capacity(), and Character::volume_carried().

◆ get_remaining_chapters()

int item::get_remaining_chapters ( const Character ch) const

Get the number of unread chapters.

If the item is no book or has no chapters, it returns 0. This is a per-character setting, different characters may have different number of unread chapters.

Definition at line 7097 of file item.cpp.

7098{
7099 const std::string var = string_format( "remaining-chapters-%d", ch.getID().get_value() );
7100 return get_var( var, get_chapters() );
7101}

References get_chapters(), character_id::get_value(), get_var(), Character::getID(), and string_format().

Referenced by book_info(), display_name(), character_funcs::get_book_fun_for(), and mark_chapter_as_read().

◆ get_rot()

time_duration item::get_rot ( ) const
inline

Definition at line 861 of file item.h.

861 {
862 return rot;
863 }

Referenced by butchery_drops_harvest(), and has_rotten_away().

◆ get_safe_reference()

safe_reference< item > item::get_safe_reference ( )

Return a pointer-like type that's automatically invalidated if this item is destroyed or assigned-to.

Definition at line 446 of file item.cpp.

447{
448 return anchor.reference_to( this );
449}
safe_reference_anchor anchor
Definition: item.h:2173
safe_reference< T > reference_to(T *object)

References anchor, and safe_reference_anchor::reference_to().

Referenced by active_item_cache::add(), and explosion_handler::ExplosionProcess::move_entity().

◆ get_shelf_life()

time_duration item::get_shelf_life ( ) const

Get the shelf life of the item.

Definition at line 5519 of file item.cpp.

5520{
5521 if( goes_bad() ) {
5522 if( is_food() ) {
5523 return get_comestible()->spoils;
5524 } else if( is_corpse() ) {
5525 return 24_hours;
5526 }
5527 }
5528 return 0_turns;
5529}

References get_comestible(), goes_bad(), is_corpse(), and is_food().

Referenced by basic_info(), calc_rot(), food_info(), get_freshness_description(), get_relative_rot(), process_corpse(), set_relative_rot(), spoilage_sort_order(), and stacks_with().

◆ get_side()

side item::get_side ( ) const

Returns side item currently worn on.

Returns BOTH if item is not sided or no side currently set

Definition at line 808 of file item.cpp.

809{
810 // MSVC complains if directly cast double to enum
811 return static_cast<side>( static_cast<int>( get_var( "lateral",
812 static_cast<int>( side::BOTH ) ) ) );
813}
side
Definition: bodypart.h:66

References BOTH, and get_var().

Referenced by display_name(), get_covered_body_parts(), on_wear(), and swap_side().

◆ get_sizing()

item::sizing item::get_sizing ( const Character p,
bool  wearable 
) const

Definition at line 1177 of file item.cpp.

1178{
1179 if( wearable ) {
1180 const bool small = p.get_size() == MS_TINY;
1181 const bool big = p.get_size() == MS_HUGE;
1182
1183 // due to the iterative nature of these features, something can fit and be undersized/oversized
1184 // but that is fine because we have separate logic to adjust encumberance per each. One day we
1185 // may want to have fit be a flag that only applies if a piece of clothing is sized for you as there
1186 // is a bit of cognitive dissonance when something 'fits' and is 'oversized' and the same time
1187 const bool undersize = has_flag( flag_UNDERSIZE );
1188 const bool oversize = has_flag( flag_OVERSIZE );
1189
1190 if( undersize ) {
1191 if( small ) {
1193 } else if( big ) {
1195 } else {
1197 }
1198 } else if( oversize ) {
1199 if( big ) {
1201 } else if( small ) {
1203 } else {
1205 }
1206 } else {
1207 if( big ) {
1209 } else if( small ) {
1211 } else {
1213 }
1214 }
1215 }
1216 return sizing::not_wearable;
1217
1218}
m_size get_size() const override
Get size class of character.
Definition: character.cpp:572
@ MS_TINY
Definition: creature.h:58
@ MS_HUGE
Definition: creature.h:62
static const std::string flag_UNDERSIZE("UNDERSIZE")
static const std::string flag_OVERSIZE("OVERSIZE")

References big_sized_big_char, big_sized_human_char, big_sized_small_char, flag_OVERSIZE(), flag_UNDERSIZE(), Character::get_size(), has_flag(), human_sized_big_char, human_sized_human_char, human_sized_small_char, MS_HUGE, MS_TINY, not_wearable, small_sized_big_char, small_sized_human_char, and small_sized_small_char.

Referenced by armor_fit_info(), armor_info(), get_encumber_when_containing(), and tname().

◆ get_storage()

units::volume item::get_storage ( ) const

Returns the storage amount (islot_armor::storage) that this item provides when worn.

For non-armor it returns 0. The storage amount increases the volume capacity of the character that wears the item.

Definition at line 5732 of file item.cpp.

5733{
5734 const islot_armor *t = find_armor_data();
5735 if( t == nullptr ) {
5736 return is_pet_armor() ? type->pet_armor->storage : 0_ml;
5737 }
5738 units::volume storage = t->storage;
5740 storage += std::lround( mod ) * units::legacy_volume_factor;
5741
5742 return storage;
5743}
@ clothing_mod_type_storage
Definition: clothing_mod.h:24

References clothing_mod_type_storage, find_armor_data(), get_clothing_mod_val(), is_pet_armor(), units::legacy_volume_factor, itype::pet_armor, islot_armor::storage, and type.

Referenced by animal_armor_info(), armor_info(), armor_inventory_preset::armor_inventory_preset(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), get_encumber(), get_total_capacity(), monexamine::give_items_to(), pickup::obtain_and_tokenize_items(), om_carry_weight_to_trips(), tutorial_game::post_action(), pickup::reorder_for_dropping(), Character::takeoff(), and sew_advanced_actor::use().

◆ get_techniques()

std::set< matec_id > item::get_techniques ( ) const

Returns all the martial art techniques that this items supports.

Definition at line 5475 of file item.cpp.

5476{
5477 std::set<matec_id> result = type->techniques;
5478 result.insert( techniques.begin(), techniques.end() );
5479 return result;
5480}

References techniques, itype::techniques, and type.

Referenced by character_martial_arts::get_all_techniques().

◆ get_thickness()

int item::get_thickness ( ) const

Returns the islot_armor::thickness value, or 0 for non-armor.

Thickness is are relative value that affects the items resistance against bash / cutting / bullet damage.

Definition at line 5909 of file item.cpp.

5910{
5911 const islot_armor *t = find_armor_data();
5912 if( t == nullptr ) {
5913 return is_pet_armor() ? type->pet_armor->thickness : 0;
5914 }
5915 return t->thickness;
5916}
int thickness
TODO: document me.
Definition: itype.h:259

References find_armor_data(), is_pet_armor(), itype::pet_armor, islot_armor::thickness, and type.

Referenced by bash_resist(), bullet_resist(), cut_resist(), clothing_mod::get_mod_val(), and tutorial_game::post_action().

◆ get_total_capacity()

units::volume item::get_total_capacity ( ) const

It returns the maximum volume of any contents, including liquids, ammo, magazines, weapons, etc.

Definition at line 8409 of file item.cpp.

8410{
8412
8413 // Consider various iuse_actors which add containing capability
8414 // Treating these two as special cases for now; if more appear in the
8415 // future then this probably warrants a new method on use_function to
8416 // access this information generically.
8417 if( is_bandolier() ) {
8418 result += dynamic_cast<const bandolier_actor *>
8419 ( type->get_use( "bandolier" )->get_actor_ptr() )->max_stored_volume();
8420 }
8421
8422 if( is_holster() ) {
8423 result += dynamic_cast<const holster_actor *>
8424 ( type->get_use( "holster" )->get_actor_ptr() )->max_stored_volume();
8425 }
8426
8427 return result;
8428}
bool is_holster() const
Definition: item.cpp:6577

References use_function::get_actor_ptr(), get_container_capacity(), get_storage(), itype::get_use(), is_bandolier(), is_holster(), and type.

Referenced by armor_info(), and get_encumber_when_containing().

◆ get_uncraft_components()

std::vector< item_comp > item::get_uncraft_components ( ) const

Returns a list of components used to craft this item or the default components if it wasn't player-crafted.

Definition at line 10057 of file item.cpp.

10058{
10059 std::vector<item_comp> ret;
10060 if( components.empty() ) {
10061 //If item wasn't crafted with specific components use default recipe
10062 std::vector<std::vector<item_comp>> recipe = recipe_dictionary::get_uncraft(
10064 for( std::vector<item_comp> &component : recipe ) {
10065 ret.push_back( component.front() );
10066 }
10067 } else {
10068 //Make a new vector of components from the registered components
10069 for( const item &component : components ) {
10070 auto iter = std::find_if( ret.begin(), ret.end(), [component]( item_comp & obj ) {
10071 return obj.type == component.typeId();
10072 } );
10073
10074 if( iter != ret.end() ) {
10075 iter->count += component.count();
10076 } else {
10077 ret.push_back( item_comp( component.typeId(), component.count() ) );
10078 }
10079 }
10080 }
10081 return ret;
10082}

References components, component::count, recipe::disassembly_requirements(), requirement_data::get_components(), recipe_dictionary::get_uncraft(), cata::hash64_detail::ret, and typeId().

Referenced by disassemble_inventory_preset::disassemble_inventory_preset(), and stacks_with().

◆ get_usable_item()

item * item::get_usable_item ( const std::string &  use_name)

Checks this item and its contents (recursively) for types that have use_function with type use_name.

Returns the first item that does have such type or nullptr if none found.

Definition at line 7974 of file item.cpp.

7975{
7976 item *ret = nullptr;
7978 [&ret, &use_name]( item * it ) {
7979 if( it == nullptr ) {
7980 return VisitResponse::SKIP;
7981 }
7982 if( it->get_use_internal( use_name ) ) {
7983 ret = it;
7984 return VisitResponse::ABORT;
7985 }
7986 return VisitResponse::NEXT;
7987 } );
7988
7989 return ret;
7990}
const use_function * get_use_internal(const std::string &use_name) const
Definition: item.cpp:7966

References get_use_internal(), NEXT, cata::hash64_detail::ret, SKIP, and visitable< item >::visit_items().

Referenced by game::butcher(), activity_handlers::firstaid_finish(), Character::invoke_item(), activity_handlers::longsalvage_finish(), item_action_generator::map_actions_to_items(), activity_handlers::repair_item_finish(), and activity_handlers::start_fire_finish().

◆ get_use()

const use_function * item::get_use ( const std::string &  use_name) const

Returns the pointer to use_function with name use_name assigned to the type of this item or any of its contents.

Checks contents recursively. Returns nullptr if not found.

Definition at line 7948 of file item.cpp.

7949{
7950 const use_function *fun = nullptr;
7952 [&fun, &use_name]( const item * it ) {
7953 if( it == nullptr ) {
7954 return VisitResponse::SKIP;
7955 }
7956 fun = it->get_use_internal( use_name );
7957 if( fun != nullptr ) {
7958 return VisitResponse::ABORT;
7959 }
7960 return VisitResponse::NEXT;
7961 } );
7962
7963 return fun;
7964}

References ABORT, get_use_internal(), NEXT, SKIP, and visitable< item >::visit_items().

Referenced by active_item_cache::add(), game::butcher(), color_in_inventory(), activity_handlers::firstaid_finish(), iuse_transform::info(), activity_handlers::longsalvage_finish(), item_action_generator::map_actions_to_items(), on_takeoff(), on_wear(), process_tool(), read(), active_item_cache::remove(), activity_handlers::repair_item_finish(), sleep(), activity_handlers::start_fire_finish(), avatar::wield(), avatar_action::wield(), and npc::wield_better_weapon().

◆ get_use_internal()

const use_function * item::get_use_internal ( const std::string &  use_name) const
private

Definition at line 7966 of file item.cpp.

7967{
7968 if( type != nullptr ) {
7969 return type->get_use( use_name );
7970 }
7971 return nullptr;
7972}

References itype::get_use(), and type.

Referenced by get_usable_item(), and get_use().

◆ get_var() [1/4]

std::string item::get_var ( const std::string &  name) const

Get the variable, if it does not exists, returns an empty string.

Definition at line 1070 of file item.cpp.

1071{
1072 return get_var( name, "" );
1073}

References get_var(), and om_direction::name().

◆ get_var() [2/4]

std::string item::get_var ( const std::string &  name,
const std::string &  default_value 
) const

Definition at line 1061 of file item.cpp.

1062{
1063 const auto it = item_vars.find( name );
1064 if( it == item_vars.end() ) {
1065 return default_value;
1066 }
1067 return it->second;
1068}

References item_vars, and om_direction::name().

◆ get_var() [3/4]

tripoint item::get_var ( const std::string &  name,
const tripoint default_value 
) const

Definition at line 1044 of file item.cpp.

1045{
1046 const auto it = item_vars.find( name );
1047 if( it == item_vars.end() ) {
1048 return default_value;
1049 }
1050 std::vector<std::string> values = string_split( it->second, ',' );
1051 return tripoint( atoi( values[0].c_str() ),
1052 atoi( values[1].c_str() ),
1053 atoi( values[2].c_str() ) );
1054}
std::vector< std::string > string_split(const std::string &text_in, char delim_in)
Split string by delimiter.

References item_vars, om_direction::name(), and string_split().

◆ get_var() [4/4]

◆ get_warmth()

int item::get_warmth ( ) const

Returns the warmth value that this item has when worn.

See player class for temperature related code, or player::warmth. Returned values should be positive. A value of 0 indicates no warmth from this item at all (this is also the default for non-armor).

Definition at line 5918 of file item.cpp.

5919{
5920 const islot_armor *t = find_armor_data();
5921 if( t == nullptr ) {
5922 return 0;
5923 }
5924 int result = t->warmth;
5925
5927
5928 return result;
5929}
@ clothing_mod_type_warmth
Definition: clothing_mod.h:23
int warmth
How much warmth this item provides.
Definition: itype.h:271

References clothing_mod_type_warmth, find_armor_data(), get_clothing_mod_val(), and islot_armor::warmth.

Referenced by armor_info(), armor_inventory_preset::armor_inventory_preset(), behavior::character_oracle_t::can_wear_warmer_clothes(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), sew_advanced_actor::use(), and Character::warmth().

◆ get_weight_capacity_bonus()

units::mass item::get_weight_capacity_bonus ( ) const

Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides when worn.

For non-armor it returns 0. The bonus is added to the total weight capacity of the character that wears the item.

Definition at line 5754 of file item.cpp.

5755{
5756 const islot_armor *t = find_armor_data();
5757 if( t == nullptr ) {
5758 return 0_gram;
5759 }
5760 return t->weight_capacity_bonus;
5761}
units::mass weight_capacity_bonus
Bonus to weight capacity.
Definition: itype.h:283

References find_armor_data(), and islot_armor::weight_capacity_bonus.

Referenced by armor_info().

◆ get_weight_capacity_modifier()

float item::get_weight_capacity_modifier ( ) const

Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides when worn.

For non-armor it returns 1. The modifier is multiplied with the weight capacity of the character that wears the item.

Definition at line 5745 of file item.cpp.

5746{
5747 const islot_armor *t = find_armor_data();
5748 if( t == nullptr ) {
5749 return 1;
5750 }
5751 return t->weight_capacity_modifier;
5752}
float weight_capacity_modifier
Factor modifiying weight capacity.
Definition: itype.h:279

References find_armor_data(), and islot_armor::weight_capacity_modifier.

Referenced by armor_info().

◆ getlight()

bool item::getlight ( float &  luminance,
units::angle width,
units::angle direction 
) const

Directional light emission of the item.

Parameters
luminanceThe amount of light (see lightmap.cpp)
widthIf greater 0, the light is emitted in an arc, this is the angle of it.
directionThe direction of the light arc. In degrees.

Definition at line 8363 of file item.cpp.

8364{
8365 luminance = 0;
8366 width = 0_degrees;
8367 direction = 0_degrees;
8368 if( light.luminance > 0 ) {
8369 luminance = static_cast<float>( light.luminance );
8370 if( light.width > 0 ) { // width > 0 is a light arc
8371 width = units::from_degrees( light.width );
8373 }
8374 return true;
8375 } else {
8376 const int lumint = getlight_emit();
8377 if( lumint > 0 ) {
8378 luminance = static_cast<float>( lumint );
8379 return true;
8380 }
8381 }
8382 return false;
8383}
light_emission light
Definition: item.h:2237
int getlight_emit() const
How much light (see lightmap.cpp) the item emits (it's assumed to be circular).
Definition: item.cpp:8385
direction
Definition: line.h:39
constexpr quantity< double, angle_in_radians_tag > from_degrees(const value_type v)
Definition: units_angle.h:31
unsigned short luminance
Definition: item.h:90
short direction
Definition: item.h:92
short width
Definition: item.h:91

References light_emission::direction, units::from_degrees(), getlight_emit(), light, light_emission::luminance, and light_emission::width.

◆ getlight_emit()

int item::getlight_emit ( ) const

How much light (see lightmap.cpp) the item emits (it's assumed to be circular).

Definition at line 8385 of file item.cpp.

8386{
8387 float lumint = type->light_emission;
8388
8389 if( lumint == 0 ) {
8390 return 0;
8391 }
8392 if( has_flag( flag_CHARGEDIM ) && is_tool() && !has_flag( flag_USE_UPS ) ) {
8393 // Falloff starts at 1/5 total charge and scales linearly from there to 0.
8394 if( ammo_capacity() && ammo_remaining() < ( ammo_capacity() / 5 ) ) {
8395 lumint *= ammo_remaining() * 5.0 / ammo_capacity();
8396 }
8397 }
8398 return lumint;
8399}
static const std::string flag_CHARGEDIM("CHARGEDIM")
unsigned light_emission
Definition: itype.h:1000

References ammo_capacity(), ammo_remaining(), flag_CHARGEDIM(), flag_USE_UPS(), has_flag(), is_tool(), itype::light_emission, and type.

Referenced by Character::active_light(), and getlight().

◆ goes_bad()

bool item::goes_bad ( ) const

whether an item is perishable (can rot)

Definition at line 5498 of file item.cpp.

5499{
5502 }
5503 if( has_flag( flag_PROCESSING ) ) {
5504 return false;
5505 }
5506 if( is_corpse() ) {
5507 // Corpses rot only if they are made of rotting materials
5509 }
5510 return is_food() && get_comestible()->spoils != 0_turns;
5511}
bool made_of_any(const std::set< material_id > &mat_idents) const
Check we are made of at least one of a set (e.g.
Definition: item.cpp:6435
static const std::string flag_PROCESSING("PROCESSING")
bool goes_bad_cache_fetch()
Definition: item.cpp:334
bool goes_bad_cache_is_for(const item *i)
Definition: item.cpp:348
std::set< material_id > get_rotting()
Definition: material.cpp:327

References flag_PROCESSING(), get_comestible(), materials::get_rotting(), item_internal::goes_bad_cache_fetch(), item_internal::goes_bad_cache_is_for(), has_flag(), is_corpse(), is_food(), and made_of_any().

Referenced by actualize_rot(), basic_info(), crafting::can_disassemble(), complete_craft(), food_info(), get_most_rotten_component(), get_relative_rot(), get_shelf_life(), goes_bad_after_opening(), item_internal::goes_bad_cache_set(), item(), set_relative_rot(), spoilage_sort_order(), stacks_with(), and tname().

◆ goes_bad_after_opening()

bool item::goes_bad_after_opening ( ) const

whether an item is perishable (can rot), even if it is currently in a preserving container

Definition at line 5513 of file item.cpp.

5514{
5515 return goes_bad() || ( type->container && type->container->preserves &&
5516 !contents.empty() && contents.front().goes_bad() );
5517}

References itype::container, contents, item_contents::empty(), item_contents::front(), goes_bad(), and type.

◆ gun_all_modes()

std::map< gun_mode_id, gun_mode > item::gun_all_modes ( ) const

Get all possible modes for this gun inclusive of any attached gunmods.

Definition at line 7839 of file item.cpp.

7840{
7841 std::map<gun_mode_id, gun_mode> res;
7842
7843 if( !is_gun() || is_gunmod() ) {
7844 return res;
7845 }
7846
7847 std::vector<const item *> opts = gunmods();
7848 opts.push_back( this );
7849
7850 for( const item *e : opts ) {
7851
7852 // handle base item plus any auxiliary gunmods
7853 if( e->is_gun() ) {
7854 for( const std::pair<const gun_mode_id, gun_modifier_data> &m : e->type->gun->modes ) {
7855 // prefix attached gunmods, e.g. M203_DEFAULT to avoid index key collisions
7856 std::string prefix = e->is_gunmod() ? ( std::string( e->typeId() ) += "_" ) : "";
7857 std::transform( prefix.begin(), prefix.end(), prefix.begin(),
7858 static_cast<int( * )( int )>( toupper ) );
7859
7860 const int qty = m.second.qty();
7861
7862 res.emplace( gun_mode_id( prefix + m.first.str() ), gun_mode( m.second.name(),
7863 const_cast<item *>( e ),
7864 qty, m.second.flags() ) );
7865 }
7866
7867 // non-auxiliary gunmods may provide additional modes for the base item
7868 } else if( e->is_gunmod() ) {
7869 for( const std::pair<const gun_mode_id, gun_modifier_data> &m : e->type->gunmod->mode_modifier ) {
7870 //checks for melee gunmod, points to gunmod
7871 if( m.first == gun_mode_REACH ) {
7872 res.emplace( m.first, gun_mode { m.second.name(), const_cast<item *>( e ),
7873 m.second.qty(), m.second.flags() } );
7874 //otherwise points to the parent gun, not the gunmod
7875 } else {
7876 res.emplace( m.first, gun_mode { m.second.name(), const_cast<item *>( this ),
7877 m.second.qty(), m.second.flags() } );
7878 }
7879 }
7880 }
7881 }
7882
7883 return res;
7884}
static const gun_mode_id gun_mode_REACH("REACH")
string_id< gun_mode > gun_mode_id
Definition: type_id.h:68

References gun_mode_REACH, gunmods(), is_gun(), is_gunmod(), prefix, and iexamine::transform().

Referenced by target_ui::action_switch_mode(), npc_ai::best_mode_for_range(), can_fire_turret(), npc::confident_shoot_range(), gun_cycle_mode(), gun_get_mode(), gun_set_mode(), game::handle_action(), and reach_range().

◆ gun_current_mode()

gun_mode item::gun_current_mode ( ) const

Get the current mode for this gun (or an invalid mode if item is not a gun)

Definition at line 7898 of file item.cpp.

7899{
7900 return gun_get_mode( gun_get_mode_id() );
7901}
gun_mode_id gun_get_mode_id() const
Get id of mode a gun is currently set to, e.g.
Definition: item.cpp:7903
gun_mode gun_get_mode(const gun_mode_id &mode) const
Check if gun supports a specific mode returning an invalid/empty mode if not.
Definition: item.cpp:7886

References gun_get_mode(), and gun_get_mode_id().

Referenced by avatar_action::can_fire_weapon(), aim_activity_actor::do_turn(), target_ui::ensure_ranged_gun_mode(), npc::execute_action(), aim_activity_actor::finish(), fire(), turret_data::fire(), character_funcs::fmt_wielded_weapon(), info(), aim_activity_actor::load_RAS_weapon(), npc::method_of_attack(), target_ui::panel_fire_mode_aim(), target_ui::panel_gun_info(), turret_data::post_fire(), turret_data::prepare_fire(), print_aim(), turret_data::query(), gun_actor::shoot(), target_ui::update_ammo_range_from_gun_mode(), and target_ui::update_status().

◆ gun_cycle_mode()

void item::gun_cycle_mode ( )

Switch to the next available firing mode.

Definition at line 7920 of file item.cpp.

7921{
7922 if( !is_gun() || is_gunmod() ) {
7923 return;
7924 }
7925
7926 const gun_mode_id cur = gun_get_mode_id();
7927 const std::map<gun_mode_id, gun_mode> modes = gun_all_modes();
7928
7929 for( auto iter = modes.begin(); iter != modes.end(); ++iter ) {
7930 if( iter->first == cur ) {
7931 if( std::next( iter ) == modes.end() ) {
7932 break;
7933 }
7934 gun_set_mode( std::next( iter )->first );
7935 return;
7936 }
7937 }
7938 gun_set_mode( modes.begin()->first );
7939
7940 return;
7941}
std::map< gun_mode_id, gun_mode > gun_all_modes() const
Get all possible modes for this gun inclusive of any attached gunmods.
Definition: item.cpp:7839
bool gun_set_mode(const gun_mode_id &mode)
Try to set the mode for a gun, returning false if no such mode is possible.
Definition: item.cpp:7911

References gun_all_modes(), gun_get_mode_id(), gun_set_mode(), is_gun(), and is_gunmod().

Referenced by target_ui::ensure_ranged_gun_mode(), and game::handle_action().

◆ gun_damage()

damage_instance item::gun_damage ( bool  with_ammo = true) const

Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods.

Returns empty instance on non-gun items.

Definition at line 7280 of file item.cpp.

7281{
7282 if( !is_gun() ) {
7283 return damage_instance();
7284 }
7285 damage_instance ret = type->gun->damage;
7286
7287 for( const item *mod : gunmods() ) {
7288 ret.add( mod->type->gunmod->damage );
7289 }
7290
7291 if( with_ammo && ammo_data() ) {
7292 ret.add( ammo_data()->ammo->damage );
7293 }
7294
7295 int item_damage = damage_level( 4 );
7296 if( item_damage > 0 ) {
7297 // TODO: This isn't a good solution for multi-damage guns/ammos
7298 for( damage_unit &du : ret ) {
7299 if( du.amount <= 1.0 ) {
7300 continue;
7301 }
7302 du.amount = std::max<float>( 1.0f, du.amount - item_damage * 2 );
7303 }
7304 }
7305
7306 return ret;
7307}

References ammo_data(), damage_level(), itype::gun, gunmods(), is_gun(), cata::hash64_detail::ret, and type.

Referenced by gun_info(), ideal_ranged_dps(), make_gun_projectile(), and weapon_inventory_preset::weapon_inventory_preset().

◆ gun_dispersion()

int item::gun_dispersion ( bool  with_ammo = true,
bool  with_scaling = true 
) const

Summed dispersion of a gun, including values from mods.

Returns 0 on non-gun items.

Definition at line 7233 of file item.cpp.

7234{
7235 if( !is_gun() ) {
7236 return 0;
7237 }
7238 int dispersion_sum = type->gun->dispersion;
7239 for( const item *mod : gunmods() ) {
7240 dispersion_sum += mod->type->gunmod->dispersion;
7241 }
7242 int dispPerDamage = get_option< int >( "DISPERSION_PER_GUN_DAMAGE" );
7243 dispersion_sum += damage_level( 4 ) * dispPerDamage;
7244 dispersion_sum = std::max( dispersion_sum, 0 );
7245 if( with_ammo && ammo_data() ) {
7246 dispersion_sum += ammo_data()->ammo->dispersion;
7247 }
7248 if( !with_scaling ) {
7249 return dispersion_sum;
7250 }
7251
7252 // Dividing dispersion by 15 temporarily as a gross adjustment,
7253 // will bake that adjustment into individual gun definitions in the future.
7254 // Absolute minimum gun dispersion is 1.
7255 double divider = get_option< float >( "GUN_DISPERSION_DIVIDER" );
7256 dispersion_sum = std::max( static_cast<int>( std::round( dispersion_sum / divider ) ), 1 );
7257
7258 return dispersion_sum;
7259}

References itype::ammo, ammo_data(), damage_level(), itype::gun, gunmods(), is_gun(), and type.

Referenced by gun_info().

◆ gun_get_mode()

gun_mode item::gun_get_mode ( const gun_mode_id mode) const

Check if gun supports a specific mode returning an invalid/empty mode if not.

Definition at line 7886 of file item.cpp.

7887{
7888 if( is_gun() ) {
7889 for( const std::pair<const gun_mode_id, gun_mode> &e : gun_all_modes() ) {
7890 if( e.first == mode ) {
7891 return e.second;
7892 }
7893 }
7894 }
7895 return gun_mode();
7896}

References gun_all_modes(), and is_gun().

Referenced by mattack::frag(), gun_current_mode(), mattack::rifle(), and mattack::tankgun().

◆ gun_get_mode_id()

gun_mode_id item::gun_get_mode_id ( ) const

Get id of mode a gun is currently set to, e.g.

DEFAULT, AUTO, BURST

Definition at line 7903 of file item.cpp.

7904{
7905 if( !is_gun() || is_gunmod() ) {
7906 return gun_mode_id();
7907 }
7908 return gun_mode_id( get_var( GUN_MODE_VAR_NAME, "DEFAULT" ) );
7909}
static const std::string GUN_MODE_VAR_NAME("item::mode")

References get_var(), GUN_MODE_VAR_NAME(), is_gun(), and is_gunmod().

Referenced by target_ui::action_switch_mode(), gun_current_mode(), and gun_cycle_mode().

◆ gun_info()

void item::gun_info ( const item mod,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2017 of file item.cpp.

2019{
2020 const std::string space = " ";
2021 const islot_gun &gun = *mod->type->gun;
2022 const Skill &skill = *mod->gun_skill();
2023 avatar &viewer = get_avatar();
2024
2025 // many statistics are dependent upon loaded ammo
2026 // if item is unloaded (or is RELOAD_AND_SHOOT) shows approximate stats using default ammo
2027 const item *loaded_mod = mod;
2028 item tmp;
2029 if( mod->ammo_required() && !mod->ammo_remaining() ) {
2030 tmp = *mod;
2031 tmp.ammo_set( mod->magazine_current() ? tmp.common_ammo_default() : tmp.ammo_default() );
2032 if( tmp.ammo_data() == nullptr ) {
2034 info.emplace_back( "GUN",
2035 _( "Weapon <bad>can't be loaded in its current state</bad>." ) );
2036 return;
2037 }
2038 loaded_mod = &tmp;
2039 if( parts->test( iteminfo_parts::GUN_DEFAULT_AMMO ) ) {
2041 info.emplace_back( "GUN",
2042 _( "Weapon is <bad>not loaded</bad>, so stats below assume the default ammo: " ),
2043 string_format( "<stat>%s</stat>",
2044 loaded_mod->ammo_data()->nname( 1 ) ) );
2045 }
2046 }
2047
2048 const itype *curammo = loaded_mod->ammo_data();
2049 if( mod->ammo_required() && !curammo ) {
2050 debugmsg( "curammo is nullptr in item::gun_info()" );
2051 return;
2052 }
2053 damage_unit gun_du = gun_damage( false ).damage_units.front();
2054
2056
2057 const damage_unit &ammo_du = curammo != nullptr
2058 ? curammo->ammo->damage.damage_units.front()
2059 : damage_unit( DT_STAB, 0 );
2060
2061 if( parts->test( iteminfo_parts::GUN_DAMAGE ) ) {
2063 info.push_back( iteminfo( "GUN", _( "<bold>Ranged damage</bold>: " ), "", iteminfo::no_newline,
2064 gun_du.amount ) );
2065 }
2066
2067 if( mod->ammo_required() ) {
2068 // ammo_damage, sum_of_damage, and ammo_mult not shown so don't need to translate.
2070 assert( curammo ); // Appease clang-tidy
2071 damage_instance ammo_dam = curammo->ammo->damage;
2072 info.push_back( iteminfo( "GUN", "ammo_damage", "",
2074 iteminfo::show_plus, ammo_du.amount ) );
2075 }
2076
2077 if( parts->test( iteminfo_parts::GUN_DAMAGE_TOTAL ) ) {
2078 // Intentionally not using total_damage() as it applies multipliers
2079 info.push_back( iteminfo( "GUN", "sum_of_damage", _( " = <num>" ),
2081 gun_du.amount + ammo_du.amount ) );
2082 }
2083 }
2084 info.back().bNewLine = true;
2085 avatar &you = get_avatar();
2086 int max_gun_range = loaded_mod->gun_range( &you );
2087 if( max_gun_range > 0 && parts->test( iteminfo_parts::GUN_MAX_RANGE ) ) {
2088 info.emplace_back( "GUN", _( "Maximum range: " ), "<num>", iteminfo::no_flags,
2089 max_gun_range );
2090 }
2091
2092 // TODO: This doesn't cover multiple damage types
2093 if( parts->test( iteminfo_parts::GUN_ARMORPIERCE ) ) {
2094 info.push_back( iteminfo( "GUN", _( "Armor-pierce: " ), "",
2096 }
2097 if( mod->ammo_required() ) {
2098 assert( curammo ); // Appease clang-tidy
2099 int ammo_pierce = get_ranged_pierce( *curammo->ammo );
2100 // ammo_armor_pierce and sum_of_armor_pierce don't need to translate.
2102 info.push_back( iteminfo( "GUN", "ammo_armor_pierce", "",
2104 iteminfo::show_plus, ammo_pierce ) );
2105 }
2107 info.push_back( iteminfo( "GUN", "sum_of_armor_pierce", _( " = <num>" ),
2109 get_ranged_pierce( gun ) + ammo_pierce ) );
2110 }
2111 }
2112 info.back().bNewLine = true;
2113
2114 if( parts->test( iteminfo_parts::GUN_DAMAGEMULT ) ) {
2115 info.push_back( iteminfo( "GUN", _( "Damage multiplier: " ), "",
2117 gun_du.damage_multiplier ) );
2118 }
2119
2120 if( mod->ammo_required() ) {
2122 info.push_back( iteminfo( "GUN", "ammo_mult", "*",
2124 ammo_du.damage_multiplier ) );
2125 }
2126
2128 info.push_back( iteminfo( "GUN", "sum_of_damage", _( " = <num>" ),
2130 gun_du.damage_multiplier * ammo_du.damage_multiplier ) );
2131 }
2132 }
2133 info.back().bNewLine = true;
2134
2135 if( parts->test( iteminfo_parts::GUN_ARMORMULT ) ) {
2136 info.push_back( iteminfo( "GUN", _( "Armor multiplier: " ), "",
2138 gun_du.res_mult ) );
2139 }
2140 if( mod->ammo_required() ) {
2142 info.push_back( iteminfo( "GUN", "ammo_armor_mult", _( "*<num>" ),
2145 ammo_du.res_mult ) );
2146 }
2148 info.push_back( iteminfo( "GUN", "final_armor_mult", _( " = <num>" ),
2150 gun_du.res_mult * ammo_du.res_mult ) );
2151 }
2152 }
2153 info.back().bNewLine = true;
2154
2155 if( parts->test( iteminfo_parts::GUN_DISPERSION ) ) {
2156 info.push_back( iteminfo( "GUN", _( "Dispersion: " ), "",
2158 mod->gun_dispersion( false, false ) ) );
2159 }
2160 if( mod->ammo_required() ) {
2161 int ammo_dispersion = curammo->ammo->dispersion;
2162 // ammo_dispersion and sum_of_dispersion don't need to translate.
2164 info.push_back( iteminfo( "GUN", "ammo_dispersion", "",
2167 ammo_dispersion ) );
2168 }
2170 info.push_back( iteminfo( "GUN", "sum_of_dispersion", _( " = <num>" ),
2172 loaded_mod->gun_dispersion( true, false ) ) );
2173 info.push_back( iteminfo( "GUN", "eff_dispersion", _( " (effective: <num>)" ),
2175 static_cast<int>( ranged::get_weapon_dispersion( you, *this ).max() ) ) );
2176 }
2177 }
2178 info.back().bNewLine = true;
2179
2180 // if effective sight dispersion differs from actual sight dispersion display both
2181 int act_disp = mod->sight_dispersion();
2182 int eff_disp = ranged::effective_dispersion( you, act_disp );
2183 int adj_disp = eff_disp - act_disp;
2184
2186 info.push_back( iteminfo( "GUN", _( "Sight dispersion: " ), "",
2188 act_disp ) );
2189
2190 if( adj_disp ) {
2191 info.push_back( iteminfo( "GUN", "sight_adj_disp", "",
2193 iteminfo::no_name | iteminfo::show_plus, adj_disp ) );
2194 info.push_back( iteminfo( "GUN", "sight_eff_disp", _( " = <num>" ),
2196 eff_disp ) );
2197 }
2198 }
2199
2200 bool bipod = mod->has_flag( flag_BIPOD );
2201
2202 if( loaded_mod->gun_recoil() ) {
2204 info.emplace_back( "GUN", _( "Recoil percentage: " ), "",
2206 std::ceil( 100 * loaded_mod->gun_recoil_multiplier() ) );
2207 }
2208 if( bipod && parts->test( iteminfo_parts::GUN_RECOIL_PERCENTAGE_BIPOD ) ) {
2209 info.emplace_back( "GUN", "bipod_recoil_percentage", _( " (with bipod <num>)" ),
2211 std::ceil( 100 * loaded_mod->gun_recoil_multiplier( true ) ) );
2212 }
2213 info.back().bNewLine = true;
2214
2215 if( parts->test( iteminfo_parts::GUN_RECOIL ) ) {
2216 info.emplace_back( "GUN", _( "Effective recoil: " ), "",
2218 loaded_mod->gun_recoil() );
2219 }
2220 if( bipod && parts->test( iteminfo_parts::GUN_RECOIL_BIPOD ) ) {
2221 info.emplace_back( "GUN", "bipod_recoil", _( " (with bipod <num>)" ),
2223 loaded_mod->gun_recoil( true ) );
2224 }
2225 }
2226 info.back().bNewLine = true;
2227
2228 std::map<gun_mode_id, gun_mode> fire_modes = mod->gun_all_modes();
2229 if( parts->test( iteminfo_parts::GUN_BURST_PENALTY ) ) {
2230 if( std::any_of( fire_modes.begin(), fire_modes.end(),
2231 []( const std::pair<gun_mode_id, gun_mode> &e ) {
2232 return e.second.qty > 1 && !e.second.melee();
2233 } ) ) {
2234 info.emplace_back( "GUN", _( "Burst fire penalty: " ), "",
2236 ranged::burst_penalty( you, *this, loaded_mod->gun_recoil() ) );
2237 if( bipod ) {
2238 info.emplace_back( "GUN", "bipod_burst", _( " (with bipod <num>)" ),
2240 ranged::burst_penalty( you, *this, loaded_mod->gun_recoil( true ) ) );
2241 }
2242 }
2243 info.back().bNewLine = true;
2244 }
2245
2246 if( parts->test( iteminfo_parts::GUN_RELOAD_TIME ) ) {
2247 info.emplace_back( "GUN", _( "Reload time: " ),
2248 has_flag( flag_RELOAD_ONE ) ? _( "<num> moves per round" ) :
2249 _( "<num> moves " ),
2250 iteminfo::lower_is_better, mod->get_reload_time() );
2251 }
2252
2253 if( parts->test( iteminfo_parts::GUN_USEDSKILL ) ) {
2254 info.push_back( iteminfo( "GUN", _( "Skill used: " ),
2255 "<info>" + skill.name() + "</info>" ) );
2256 }
2257
2258 if( mod->magazine_integral() || mod->magazine_current() ) {
2259 if( mod->magazine_current() && parts->test( iteminfo_parts::GUN_MAGAZINE ) ) {
2260 info.emplace_back( "GUN", _( "Magazine: " ),
2261 string_format( "<stat>%s</stat>",
2262 mod->magazine_current()->tname() ) );
2263 }
2264 if( mod->ammo_capacity() && parts->test( iteminfo_parts::GUN_CAPACITY ) ) {
2265 for( const ammotype &at : mod->ammo_types() ) {
2266 const std::string fmt = string_format( vgettext( "<num> round of %s",
2267 "<num> rounds of %s",
2268 mod->ammo_capacity() ), at->name() );
2269 info.emplace_back( "GUN", _( "Capacity: " ), fmt, iteminfo::no_flags,
2270 mod->ammo_capacity() );
2271 }
2272 }
2273 } else if( parts->test( iteminfo_parts::GUN_TYPE ) ) {
2274 info.emplace_back( "GUN", _( "Type: " ), enumerate_as_string( mod->ammo_types().begin(),
2275 mod->ammo_types().end(), []( const ammotype & at ) {
2276 return at->name();
2278 }
2279
2280 if( mod->ammo_data() && parts->test( iteminfo_parts::AMMO_REMAINING ) ) {
2281 info.emplace_back( "AMMO", _( "Ammunition: " ), string_format( "<stat>%s</stat>",
2282 mod->ammo_data()->nname( mod->ammo_remaining() ) ) );
2283 }
2284
2285 if( mod->get_gun_ups_drain() && parts->test( iteminfo_parts::AMMO_UPSCOST ) ) {
2286 info.emplace_back( "AMMO",
2287 string_format( vgettext( "Uses <stat>%i</stat> charge of UPS per shot",
2288 "Uses <stat>%i</stat> charges of UPS per shot",
2289 mod->get_gun_ups_drain() ),
2290 mod->get_gun_ups_drain() ) );
2291 }
2292
2293 if( parts->test( iteminfo_parts::GUN_AIMING_STATS ) ) {
2295 info.emplace_back( "GUN", _( "<bold>Base aim speed</bold>: " ), "<num>", iteminfo::no_flags,
2297 for( const ranged::aim_type &type : ranged::get_aim_types( you, *mod ) ) {
2298 // Nameless aim levels don't get an entry.
2299 if( type.name.empty() ) {
2300 continue;
2301 }
2302 // For item comparison to work correctly each info object needs a
2303 // distinct tag per aim type.
2304 const std::string tag = "GUN_" + type.name;
2305 info.emplace_back( tag, string_format( "<info>%s</info>", type.name ) );
2306 int max_dispersion = ranged::get_weapon_dispersion( you, *loaded_mod ).max();
2307 int range = range_with_even_chance_of_good_hit( max_dispersion + type.threshold );
2308 info.emplace_back( tag, _( "Even chance of good hit at range: " ),
2309 _( "<num>" ), iteminfo::no_flags, range );
2310 int aim_mv = ranged::gun_engagement_moves( you, *mod, type.threshold );
2311 info.emplace_back( tag, _( "Time to reach aim level: " ), _( "<num> moves " ),
2312 iteminfo::lower_is_better, aim_mv );
2313 }
2314 }
2315
2316 if( parts->test( iteminfo_parts::GUN_FIRE_MODES ) ) {
2317 std::vector<std::string> fm;
2318 for( const std::pair<const gun_mode_id, gun_mode> &e : fire_modes ) {
2319 if( e.second.target == this && !e.second.melee() ) {
2320 fm.emplace_back( string_format( "%s (%i)", e.second.tname(), e.second.qty ) );
2321 }
2322 }
2323 if( !fm.empty() ) {
2325 info.emplace_back( "GUN", _( "<bold>Fire modes</bold>: " ) +
2326 enumerate_as_string( fm ) );
2327 }
2328 }
2329
2332 const std::set<itype_id> compat = magazine_compatible();
2333 info.emplace_back( "DESCRIPTION", _( "<bold>Compatible magazines</bold>: " ) +
2334 enumerate_as_string( compat.begin(), compat.end(), []( const itype_id & id ) {
2335 return item::nname( id );
2336 } ) );
2337 }
2338
2339 if( !gun.valid_mod_locations.empty() && parts->test( iteminfo_parts::DESCRIPTION_GUN_MODS ) ) {
2341
2342 std::string mod_str = _( "<bold>Mods</bold>: " );
2343
2344 std::map<gunmod_location, int> mod_locations = get_mod_locations();
2345
2346 int iternum = 0;
2347 for( std::pair<const gunmod_location, int> &elem : mod_locations ) {
2348 if( iternum != 0 ) {
2349 mod_str += "; ";
2350 }
2351 const int free_slots = ( elem ).second - get_free_mod_locations( elem.first );
2352 mod_str += string_format( "<bold>%d/%d</bold> %s", free_slots, elem.second,
2353 elem.first.name() );
2354 bool first_mods = true;
2355 for( const item *gmod : gunmods() ) {
2356 if( gmod->type->gunmod->location == ( elem ).first ) { // if mod for this location
2357 if( first_mods ) {
2358 mod_str += ": ";
2359 first_mods = false;
2360 } else {
2361 mod_str += ", ";
2362 }
2363 mod_str += string_format( "<stat>%s</stat>", gmod->tname() );
2364 }
2365 }
2366 iternum++;
2367 }
2368 mod_str += ".";
2369 info.push_back( iteminfo( "DESCRIPTION", mod_str ) );
2370 }
2371
2372 if( mod->casings_count() && parts->test( iteminfo_parts::DESCRIPTION_GUN_CASINGS ) ) {
2374 std::string tmp = vgettext( "Contains <stat>%i</stat> casing",
2375 "Contains <stat>%i</stat> casings", mod->casings_count() );
2376 info.emplace_back( "DESCRIPTION", string_format( tmp, mod->casings_count() ) );
2377 }
2378}
@ range
Definition: character.h:104
Definition: skill.h:33
double max() const
Definition: dispersion.cpp:20
int gun_recoil(bool bipod=false) const
Get effective recoil considering handling, loaded ammo and effects of attached gunmods.
Definition: item.cpp:7329
itype_id common_ammo_default(bool conversion=true) const
Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none ...
Definition: item.cpp:7617
int get_free_mod_locations(const gunmod_location &location) const
Number of mods that can still be installed into the given mod location, for non-guns it always return...
Definition: item.cpp:4095
damage_instance gun_damage(bool with_ammo=true) const
Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods.
Definition: item.cpp:7280
int gun_dispersion(bool with_ammo=true, bool with_scaling=true) const
Summed dispersion of a gun, including values from mods.
Definition: item.cpp:7233
double gun_recoil_multiplier(bool bipod=false) const
Get multiplier on recoil considering handling and attached gunmods.
Definition: item.cpp:7309
int gun_range(const player *p) const
The weapons range in map squares.
Definition: item.cpp:7362
bool empty() const
Whether the underlying string is empty, not matter what the context is or whether translation is need...
constexpr double MAX_RECOIL
static const std::string flag_RELOAD_ONE("RELOAD_ONE")
static const std::string flag_BIPOD("BIPOD")
@ GUN_ARMORPIERCE_LOADEDAMMO
@ GUN_RECOIL_PERCENTAGE_BIPOD
int gun_engagement_moves(const Character &who, const item &gun, int target=0, int start=MAX_RECOIL)
How many moves does it take to aim gun to the target accuracy.
Definition: ranged.cpp:583
float str_draw_damage_modifier(const item &it, const Character &p)
Definition: ranged.cpp:1034
int burst_penalty(const Character &p, const item &gun, int gun_recoil)
Definition: ranged.cpp:2163
std::vector< aim_type > get_aim_types(const Character &who, const item &gun)
Definition: ranged.cpp:1653
int effective_dispersion(const Character &who, int dispersion)
Definition: ranged.cpp:3809
dispersion_sources get_weapon_dispersion(const Character &who, const item &obj)
Get weapon's dispersion value modified accoring to character stats.
Definition: ranged.cpp:1920
double aim_per_move(const Character &who, const item &gun, double recoil)
Calculates aim improvement per move spent aiming at a given.
Definition: ranged.cpp:3908
int range_with_even_chance_of_good_hit(int dispersion)
Definition: ranged.cpp:572
float amount
Definition: damage.h:37
float res_mult
Definition: damage.h:39
std::map< gunmod_location, int > valid_mod_locations
Location for gun mods.
Definition: itype.h:520
@ no_name
Do not print the name.
Definition: item.h:149
translation name
unique string identifier for this type
Definition: itype.h:887

References _, ranged::aim_per_move(), itype::ammo, ammo_data(), ammo_default(), AMMO_REMAINING, ammo_set(), AMMO_UPSCOST, damage_unit::amount, ranged::burst_penalty(), common_ammo_default(), curammo, damage_unit::damage_multiplier, damage_instance::damage_units, debugmsg, DESCRIPTION_GUN_CASINGS, DESCRIPTION_GUN_MODS, DT_STAB, ranged::effective_dispersion(), translation::empty(), enumerate_as_string(), flag_BIPOD(), flag_RELOAD_ONE(), ranged::get_aim_types(), get_avatar(), get_free_mod_locations(), get_mod_locations(), get_ranged_pierce(), ranged::get_weapon_dispersion(), GUN_AIMING_STATS, GUN_ALLOWED_MAGAZINES, GUN_ARMORMULT, GUN_ARMORMULT_LOADEDAMMO, GUN_ARMORMULT_TOTAL, GUN_ARMORPIERCE, GUN_ARMORPIERCE_LOADEDAMMO, GUN_ARMORPIERCE_TOTAL, GUN_BURST_PENALTY, GUN_CAPACITY, gun_damage(), GUN_DAMAGE, GUN_DAMAGE_LOADEDAMMO, GUN_DAMAGE_TOTAL, GUN_DAMAGEMULT, GUN_DAMAGEMULT_AMMO, GUN_DAMAGEMULT_TOTAL, GUN_DEFAULT_AMMO, gun_dispersion(), GUN_DISPERSION, GUN_DISPERSION_LOADEDAMMO, GUN_DISPERSION_SIGHT, GUN_DISPERSION_TOTAL, ranged::gun_engagement_moves(), GUN_FIRE_MODES, GUN_MAGAZINE, GUN_MAX_RANGE, gun_range(), gun_recoil(), GUN_RECOIL, GUN_RECOIL_BIPOD, gun_recoil_multiplier(), GUN_RECOIL_PERCENTAGE, GUN_RECOIL_PERCENTAGE_BIPOD, GUN_RELOAD_TIME, GUN_TYPE, GUN_USEDSKILL, gunmods(), has_flag(), info(), insert_separation_line(), iteminfo::is_decimal, iteminfo::lower_is_better, magazine_compatible(), magazine_integral(), dispersion_sources::max(), MAX_RECOIL, itype::name, Skill::name(), itype::nname(), iteminfo::no_flags, iteminfo::no_name, iteminfo::no_newline, none, range, range_with_even_chance_of_good_hit(), damage_unit::res_mult, second, iteminfo::show_plus, sign::space, ranged::str_draw_damage_modifier(), string_format(), iteminfo_query::test(), type, islot_gun::valid_mod_locations, and vgettext().

Referenced by info().

◆ gun_noise()

item::sound_data item::gun_noise ( bool  burst = false) const

Returns the sound of the gun being fired.

Parameters
burstWhether the gun was fired in burst mode (the sound string is usually different).

Definition at line 1815 of file ranged.cpp.

1816{
1817 if( !is_gun() ) {
1818 return { 0, "" };
1819 }
1820
1821 int noise = type->gun->loudness;
1822 for( const auto mod : gunmods() ) {
1823 noise += mod->type->gunmod->loudness;
1824 }
1825 if( ammo_data() ) {
1826 noise += ammo_data()->ammo->loudness;
1827 }
1828
1829 noise = std::max( noise, 0 );
1830
1832 // Grenade launchers
1833 return { 8, _( "Thunk!" ) };
1834
1835 } else if( ammo_current() == itype_12mm || ammo_current() == itype_metal_rail ) {
1836 // Railguns
1837 return { 24, _( "tz-CRACKck!" ) };
1838
1839 } else if( ammo_current() == itype_flammable || ammo_current() == itype_66mm ||
1841 // Rocket launchers and flamethrowers
1842 return { 4, _( "Fwoosh!" ) };
1843 } else if( ammo_current() == itype_arrow ) {
1844 return { noise, _( "whizz!" ) };
1845 } else if( ammo_current() == itype_bolt ) {
1846 return { noise, _( "thonk!" ) };
1847 }
1848
1849 auto fx = ammo_effects();
1850
1851 if( fx.count( ammo_effect_LASER ) || fx.count( ammo_effect_PLASMA ) ) {
1852 if( noise < 20 ) {
1853 return { noise, _( "Fzzt!" ) };
1854 } else if( noise < 40 ) {
1855 return { noise, _( "Pew!" ) };
1856 } else if( noise < 60 ) {
1857 return { noise, _( "Tsewww!" ) };
1858 } else {
1859 return { noise, _( "Kra-kow!" ) };
1860 }
1861
1862 } else if( fx.count( ammo_effect_LIGHTNING ) ) {
1863 if( noise < 20 ) {
1864 return { noise, _( "Bzzt!" ) };
1865 } else if( noise < 40 ) {
1866 return { noise, _( "Bzap!" ) };
1867 } else if( noise < 60 ) {
1868 return { noise, _( "Bzaapp!" ) };
1869 } else {
1870 return { noise, _( "Kra-koom!" ) };
1871 }
1872
1873 } else if( fx.count( ammo_effect_WHIP ) ) {
1874 return { noise, _( "Crack!" ) };
1875
1876 } else if( noise > 0 ) {
1877 if( noise < 10 ) {
1878 return { noise, burst ? _( "Brrrip!" ) : _( "plink!" ) };
1879 } else if( noise < 150 ) {
1880 return { noise, burst ? _( "Brrrap!" ) : _( "bang!" ) };
1881 } else if( noise < 175 ) {
1882 return { noise, burst ? _( "P-p-p-pow!" ) : _( "blam!" ) };
1883 } else {
1884 return { noise, burst ? _( "Kaboom!" ) : _( "kerblam!" ) };
1885 }
1886 }
1887
1888 return { 0, "" }; // silent weapons
1889}
std::set< ammo_effect_str_id > ammo_effects(bool with_ammo=true) const
Get ammo effects for item optionally inclusive of any resulting from the loaded ammo.
Definition: item.cpp:7633
static const ammo_effect_str_id ammo_effect_WHIP("WHIP")
static const ammo_effect_str_id ammo_effect_LIGHTNING("LIGHTNING")
static const itype_id itype_12mm("12mm")
static const itype_id itype_flammable("flammable")
static const itype_id itype_m235("m235")
static const ammo_effect_str_id ammo_effect_LASER("LASER")
static const itype_id itype_40x46mm("40x46mm")
static const itype_id itype_40x53mm("40x53mm")
static const itype_id itype_bolt("bolt")
static const itype_id itype_84x246mm("84x246mm")
static const itype_id itype_metal_rail("metal_rail")
static const ammo_effect_str_id ammo_effect_PLASMA("PLASMA")
static const itype_id itype_66mm("66mm")
static const itype_id itype_arrow("arrow")

References _, itype::ammo, ammo_current(), ammo_data(), ammo_effect_LASER, ammo_effect_LIGHTNING, ammo_effect_PLASMA, ammo_effect_WHIP, ammo_effects(), itype::gun, gunmods(), is_gun(), itype_12mm, itype_40x46mm, itype_40x53mm, itype_66mm, itype_84x246mm, itype_arrow, itype_bolt, itype_flammable, itype_m235, itype_metal_rail, noise, and type.

Referenced by is_silent(), ranged::make_gun_sound_effect(), and npc::pretend_fire().

◆ gun_range() [1/2]

int item::gun_range ( bool  with_ammo = true) const

Summed range value of a gun, including values from mods.

Returns 0 on non-gun items.

Definition at line 7343 of file item.cpp.

7344{
7345 if( !is_gun() ) {
7346 return 0;
7347 }
7348 int ret = type->gun->range;
7349 for( const item *mod : gunmods() ) {
7350 ret += mod->type->gunmod->range;
7351 }
7352 if( with_ammo && ammo_data() ) {
7353 if( ammo_data()->ammo->shape ) {
7354 ret = ammo_data()->ammo->shape->get_range();
7355 } else {
7356 ret += ammo_data()->ammo->range;
7357 }
7358 }
7359 return std::min( std::max( 0, ret ), RANGE_HARD_CAP );
7360}
static constexpr int RANGE_HARD_CAP

References itype::ammo, ammo_data(), itype::gun, gunmods(), is_gun(), RANGE_HARD_CAP, cata::hash64_detail::ret, and type.

◆ gun_range() [2/2]

int item::gun_range ( const player p) const

The weapons range in map squares.

If the item has an active gunmod, it returns the range of that gunmod, the guns range is returned only when the item has no active gunmod. This function applies to guns and auxiliary gunmods. For other items, 0 is returned. It includes the range given by the ammo.

Parameters
pThe player that uses the weapon, their strength might affect this. It's optional and can be null.

Definition at line 7362 of file item.cpp.

7363{
7364 int ret = gun_range( true );
7365 if( p == nullptr ) {
7366 return ret;
7367 }
7368 if( !p->meets_requirements( *this ) ) {
7369 return 0;
7370 }
7371
7372 // Reduce bow range if player has less than minimum strength.
7373 ret *= ranged::str_draw_range_modifier( *this, *p );
7374
7375 return std::max( 0, ret );
7376}
bool meets_requirements(const item &it, const item &context=item()) const
Checks whether the character meets overall requirements to be able to use the item.
Definition: character.cpp:3533
float str_draw_range_modifier(const item &it, const Character &p)
Definition: ranged.cpp:1060

References gun_range(), Character::meets_requirements(), cata::hash64_detail::ret, and ranged::str_draw_range_modifier().

Referenced by gun_info(), gun_range(), game::list_monsters(), make_gun_projectile(), turret_data::range(), and target_ui::update_ammo_range_from_gun_mode().

◆ gun_recoil()

int item::gun_recoil ( bool  bipod = false) const

Get effective recoil considering handling, loaded ammo and effects of attached gunmods.

Parameters
bipodwhether any bipods should be considered
Returns
effective recoil (per shot) or zero if gun uses ammo and none is loaded

Definition at line 7329 of file item.cpp.

7330{
7331 if( !is_gun() || ( ammo_required() && !ammo_remaining() ) ) {
7332 return 0;
7333 }
7334
7335 int qty = type->gun->recoil;
7336 if( ammo_data() ) {
7337 qty += ammo_data()->ammo->recoil;
7338 }
7339
7340 return qty * gun_recoil_multiplier( bipod );
7341}

References itype::ammo, ammo_data(), ammo_remaining(), ammo_required(), itype::gun, gun_recoil_multiplier(), is_gun(), and type.

Referenced by calculate_dispersion(), npc::confident_gun_mode_range(), ranged::fire_gun(), and gun_info().

◆ gun_recoil_multiplier()

double item::gun_recoil_multiplier ( bool  bipod = false) const

Get multiplier on recoil considering handling and attached gunmods.

Parameters
bipodwhether any bipods should be considered
Returns
multiplier on recoil applied to shots fired from this gun

Definition at line 7309 of file item.cpp.

7310{
7311 double handling = type->gun->handling;
7312 for( const item *mod : gunmods() ) {
7313 if( bipod || !mod->has_flag( flag_BIPOD ) ) {
7314 handling += mod->type->gunmod->handling;
7315 }
7316 }
7317
7318 // Rescale from JSON units which are intentionally specified as integral values
7319 handling /= 10;
7320
7321 // Handling will almost always be above 1.0
7322 if( handling > 1.0 ) {
7323 return 1.0 / handling;
7324 } else {
7325 return 2.0 - handling;
7326 }
7327}

References flag_BIPOD(), itype::gun, gunmods(), and type.

Referenced by gun_info(), and gun_recoil().

◆ gun_set_mode()

bool item::gun_set_mode ( const gun_mode_id mode)

Try to set the mode for a gun, returning false if no such mode is possible.

Definition at line 7911 of file item.cpp.

7912{
7913 if( !is_gun() || is_gunmod() || !gun_all_modes().count( mode ) ) {
7914 return false;
7915 }
7916 set_var( GUN_MODE_VAR_NAME, mode.str() );
7917 return true;
7918}

References count(), gun_all_modes(), GUN_MODE_VAR_NAME(), is_gun(), is_gunmod(), set_var(), and string_id< T >::str().

Referenced by target_ui::action_switch_mode(), gun_cycle_mode(), avatar_funcs::gunmod_remove(), game::handle_action(), io(), and gun_actor::shoot().

◆ gun_skill()

◆ gun_type()

gun_type_type item::gun_type ( ) const

Get the type of a ranged weapon (e.g.

"rifle", "crossbow"), or empty string if non-gun

Definition at line 7195 of file item.cpp.

7196{
7197 if( !is_gun() ) {
7198 return gun_type_type( std::string() );
7199 }
7200 if( has_flag( flag_CROSSBOW ) ) {
7201 return gun_type_type( translate_marker_context( "gun_type_type", "crossbow" ) );
7202 }
7203 // TODO: move to JSON and remove extraction of this from "GUN" (via skill id)
7204 //and from "GUNMOD" (via "mod_targets") in lang/extract_json_strings.py
7205 return gun_type_type( gun_skill().str() );
7206}
The type of gun. The second "_type" suffix is only to distinguish it from item::gun_type.
Definition: itype.h:548
static const std::string flag_CROSSBOW("CROSSBOW")
#define translate_marker_context(c, x)
Same as translate_marker, but also provides a context (string literal).
Definition: translations.h:38

References flag_CROSSBOW(), gun_skill(), has_flag(), is_gun(), and translate_marker_context.

Referenced by is_gunmod_compatible().

◆ gunmod_find() [1/2]

item * item::gunmod_find ( const itype_id mod)

Get first attached gunmod matching type or nullptr if no such mod or item is not a gun.

Definition at line 7750 of file item.cpp.

7751{
7752 std::vector<item *> mods = gunmods();
7753 auto it = std::find_if( mods.begin(), mods.end(), [&mod]( item * e ) {
7754 return e->typeId() == mod;
7755 } );
7756 return it != mods.end() ? *it : nullptr;
7757}

References gunmods().

Referenced by saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), cycle_action(), gunmod_find(), is_gunmod_compatible(), tname(), volume(), and weight().

◆ gunmod_find() [2/2]

const item * item::gunmod_find ( const itype_id mod) const

Definition at line 7759 of file item.cpp.

7760{
7761 return const_cast<item *>( this )->gunmod_find( mod );
7762}
item * gunmod_find(const itype_id &mod)
Get first attached gunmod matching type or nullptr if no such mod or item is not a gun.
Definition: item.cpp:7750

References gunmod_find().

◆ gunmod_info()

void item::gunmod_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2380 of file item.cpp.

2382{
2383 if( !is_gunmod() ) {
2384 return;
2385 }
2386 const islot_gunmod &mod = *type->gunmod;
2387
2388 if( is_gun() && parts->test( iteminfo_parts::DESCRIPTION_GUNMOD ) ) {
2389 info.push_back( iteminfo( "DESCRIPTION",
2390 _( "This mod <info>must be attached to a gun</info>, "
2391 "it can not be fired separately." ) ) );
2392 }
2394 info.push_back( iteminfo( "DESCRIPTION",
2395 _( "When attached to a gun, <good>allows</good> making "
2396 "<info>reach melee attacks</info> with it." ) ) );
2397 }
2398 if( mod.dispersion != 0 && parts->test( iteminfo_parts::GUNMOD_DISPERSION ) ) {
2399 info.push_back( iteminfo( "GUNMOD", _( "Dispersion modifier: " ), "",
2401 mod.dispersion ) );
2402 }
2403 if( mod.sight_dispersion != -1 && parts->test( iteminfo_parts::GUNMOD_DISPERSION_SIGHT ) ) {
2404 info.push_back( iteminfo( "GUNMOD", _( "Sight dispersion: " ), "",
2405 iteminfo::lower_is_better, mod.sight_dispersion ) );
2406 }
2407 if( mod.aim_speed >= 0 && parts->test( iteminfo_parts::GUNMOD_AIMSPEED ) ) {
2408 info.push_back( iteminfo( "GUNMOD", _( "Aim speed: " ), "",
2409 iteminfo::lower_is_better, mod.aim_speed ) );
2410 }
2411 int total_damage = static_cast<int>( mod.damage.total_damage() );
2412 if( total_damage != 0 && parts->test( iteminfo_parts::GUNMOD_DAMAGE ) ) {
2413 info.push_back( iteminfo( "GUNMOD", _( "Damage: " ), "", iteminfo::show_plus,
2414 total_damage ) );
2415 }
2416 int pierce = get_ranged_pierce( mod );
2418 info.push_back( iteminfo( "GUNMOD", _( "Armor-pierce: " ), "", iteminfo::show_plus,
2419 pierce ) );
2420 }
2421 if( mod.handling != 0 && parts->test( iteminfo_parts::GUNMOD_HANDLING ) ) {
2422 info.emplace_back( "GUNMOD", _( "Handling modifier: " ), "",
2423 iteminfo::show_plus, mod.handling );
2424 }
2425 if( !type->mod->ammo_modifier.empty() && parts->test( iteminfo_parts::GUNMOD_AMMO ) ) {
2426 for( const ammotype &at : type->mod->ammo_modifier ) {
2427 info.push_back( iteminfo( "GUNMOD", string_format( _( "Ammo: <stat>%s</stat>" ),
2428 at->name() ) ) );
2429 }
2430 }
2431 if( mod.reload_modifier != 0 && parts->test( iteminfo_parts::GUNMOD_RELOAD ) ) {
2432 info.emplace_back( "GUNMOD", _( "Reload modifier: " ), _( "<num>%" ),
2433 iteminfo::lower_is_better, mod.reload_modifier );
2434 }
2435 if( mod.min_str_required_mod > 0 && parts->test( iteminfo_parts::GUNMOD_STRENGTH ) ) {
2436 info.push_back( iteminfo( "GUNMOD", _( "Minimum strength required modifier: " ),
2437 mod.min_str_required_mod ) );
2438 }
2439 if( !mod.add_mod.empty() && parts->test( iteminfo_parts::GUNMOD_ADD_MOD ) ) {
2441
2442 std::string mod_loc_str = _( "<bold>Adds mod locations: </bold> " );
2443
2444 std::map<gunmod_location, int> mod_locations = mod.add_mod;
2445
2446 int iternum = 0;
2447 for( std::pair<const gunmod_location, int> &elem : mod_locations ) {
2448 if( iternum != 0 ) {
2449 mod_loc_str += "; ";
2450 }
2451 mod_loc_str += string_format( "<bold>%s</bold> %s", elem.second, elem.first.name() );
2452 iternum++;
2453 }
2454 mod_loc_str += ".";
2455 info.push_back( iteminfo( "GUNMOD", mod_loc_str ) );
2456 }
2457
2459
2460 if( parts->test( iteminfo_parts::GUNMOD_USEDON ) ) {
2461 std::string used_on_str = _( "Used on: " ) +
2462 enumerate_as_string( mod.usable.begin(), mod.usable.end(), []( const gun_type_type & used_on ) {
2463 return string_format( "<info>%s</info>", used_on.name() );
2464 } );
2465 info.push_back( iteminfo( "GUNMOD", used_on_str ) );
2466 }
2467
2468 if( parts->test( iteminfo_parts::GUNMOD_LOCATION ) ) {
2469 info.push_back( iteminfo( "GUNMOD", string_format( _( "Location: %s" ),
2470 mod.location.name() ) ) );
2471 }
2472
2473 if( !mod.blacklist_mod.empty() && parts->test( iteminfo_parts::GUNMOD_BLACKLIST_MOD ) ) {
2474 std::string mod_black_str = _( "<bold>Incompatible with mod location: </bold> " );
2475
2476 int iternum = 0;
2477 for( const gunmod_location &black : mod.blacklist_mod ) {
2478 if( iternum != 0 ) {
2479 mod_black_str += ", ";
2480 }
2481 mod_black_str += string_format( "%s", black.name() );
2482 iternum++;
2483 }
2484 mod_black_str += ".";
2485 info.push_back( iteminfo( "GUNMOD", mod_black_str ) );
2486 }
2487}
cata::value_ptr< islot_gunmod > gunmod
Definition: itype.h:860
cata::value_ptr< islot_mod > mod
Definition: itype.h:855

References _, catacurses::black, DESCRIPTION_GUNMOD, DESCRIPTION_GUNMOD_REACH, enumerate_as_string(), flag_REACH_ATTACK(), get_ranged_pierce(), itype::gunmod, GUNMOD_ADD_MOD, GUNMOD_AIMSPEED, GUNMOD_AMMO, GUNMOD_ARMORPIERCE, GUNMOD_BLACKLIST_MOD, GUNMOD_DAMAGE, GUNMOD_DISPERSION, GUNMOD_DISPERSION_SIGHT, GUNMOD_HANDLING, GUNMOD_LOCATION, GUNMOD_RELOAD, GUNMOD_STRENGTH, GUNMOD_USEDON, has_flag(), info(), insert_separation_line(), is_gun(), is_gunmod(), iteminfo::lower_is_better, itype::mod, ammunition_type::name(), iteminfo::show_plus, string_format(), iteminfo_query::test(), and type.

Referenced by info().

◆ gunmods() [1/2]

◆ gunmods() [2/2]

std::vector< const item * > item::gunmods ( ) const

Definition at line 7745 of file item.cpp.

7746{
7747 return contents.gunmods();
7748}

References contents, and item_contents::gunmods().

◆ handle_craft_failure()

bool item::handle_craft_failure ( player crafter)

Handle failure during crafting.

Destroy components, lose progress, and set a new failure point.

Parameters
crafterthe crafting player.
Returns
whether the craft being worked on should be entirely destroyed

Definition at line 930 of file crafting.cpp.

931{
932 if( !is_craft() ) {
933 debugmsg( "handle_craft_failure() called on non-craft '%s.' Aborting.", tname() );
934 return false;
935 }
936
937 const double success_roll = crafter.crafting_success_roll( get_making() );
938 const int starting_components = this->components.size();
939 // Destroy at most 75% of the components, always a chance of losing 1 though
940 const size_t max_destroyed = std::max<size_t>( 1, components.size() * 3 / 4 );
941 for( size_t i = 0; i < max_destroyed; i++ ) {
942 // This shouldn't happen
943 if( components.empty() ) {
944 break;
945 }
946 // If we roll success, skip destroying a component
947 if( x_in_y( success_roll, 1.0 ) ) {
948 continue;
949 }
950 destroy_random_component( *this, crafter );
951 }
952 if( starting_components > 0 && this->components.empty() ) {
953 // The craft had components and all of them were destroyed.
954 return true;
955 }
956
957 // Minimum 25% progress lost, average 35%. Falls off exponentially
958 // Loss is scaled by the success roll
959 const double percent_progress_loss = rng_exponential( 0.25, 0.35 ) *
960 ( 1.0 - std::min( success_roll, 1.0 ) );
961 const int progess_loss = item_counter * percent_progress_loss;
962 crafter.add_msg_player_or_npc( _( "You mess up and lose %d%% progress." ),
963 _( "<npcname> messes up and loses %d%% progress." ), progess_loss / 100000 );
964 item_counter = clamp( item_counter - progess_loss, 0, 10000000 );
965
966 set_next_failure_point( crafter );
967
968 // Check if we can consume a new component and continue
969 if( !crafter.can_continue_craft( *this ) ) {
970 crafter.cancel_activity();
971 }
972 return false;
973}
bool x_in_y(const time_duration &a, const time_duration &b)
Definition: calendar.cpp:521
constexpr T clamp(const T &val, const T &min, const T &max)
Clamp first argument so that it is no lower than second and no higher than third.
Definition: cata_utility.h:149
void cancel_activity()
Definition: character.cpp:9214
const recipe & get_making() const
Get the stored recipe for in progress crafts.
Definition: item.cpp:10089
void set_next_failure_point(const player &crafter)
Calculates and sets the next failure point for an in progress craft.
Definition: crafting.cpp:904
void add_msg_player_or_npc(const std::string &player_msg, const std::string &npc_str) const override
Definition: player.cpp:369
bool can_continue_craft(item &craft)
Check if the player meets the requirements to continue the in progress craft and if unable to continu...
Definition: crafting.cpp:1161
double crafting_success_roll(const recipe &making) const
Calculate a value representing the success of the player at crafting the given recipe,...
Definition: crafting.cpp:820
static void destroy_random_component(item &craft, const player &crafter)
Definition: crafting.cpp:917
double rng_exponential(double min, double mean)
Definition: rng.cpp:55

References _, player::add_msg_player_or_npc(), player::can_continue_craft(), Character::cancel_activity(), clamp(), components, player::crafting_success_roll(), debugmsg, destroy_random_component(), get_making(), is_craft(), item_counter, rng_exponential(), set_next_failure_point(), tname(), and x_in_y().

◆ handle_pickup_ownership()

void item::handle_pickup_ownership ( Character c)

Definition at line 4476 of file item.cpp.

4477{
4478 if( is_owned_by( c ) ) {
4479 return;
4480 }
4481 // Add ownership to item if unowned
4482 if( owner.is_null() ) {
4483 set_owner( c );
4484 } else {
4486 if( !is_owned_by( c ) && &c == &you ) {
4487 std::vector<npc *> witnesses;
4488 for( npc &elem : g->all_npcs() ) {
4489 if( rl_dist( elem.pos(), you.pos() ) < MAX_VIEW_DISTANCE && elem.get_faction() &&
4490 is_owned_by( elem ) && elem.sees( you.pos() ) ) {
4491 elem.say( "<witnessed_thievery>", 7 );
4492 npc *npc_to_add = &elem;
4493 witnesses.push_back( npc_to_add );
4494 }
4495 }
4496 if( !witnesses.empty() ) {
4498 // Make sure there is only one witness
4499 for( npc &guy : g->all_npcs() ) {
4500 if( guy.get_attitude() == NPCATT_RECOVER_GOODS ) {
4501 guy.set_attitude( NPCATT_NULL );
4502 }
4503 }
4504 random_entry( witnesses )->set_attitude( NPCATT_RECOVER_GOODS );
4505 // Notify the activity that we got a witness
4506 if( c.activity && !c.activity.is_null() && c.activity.id() == ACT_PICKUP ) {
4507 c.activity.str_values.clear();
4508 c.activity.str_values.emplace_back( has_thievery_witness );
4509 }
4510 }
4511 set_owner( c );
4512 }
4513 }
4514}
const tripoint & pos() const override
Definition: character.cpp:598
bool is_owned_by(const Character &c, bool available_to_take=false) const
Definition: item.cpp:1234
void set_old_owner(const faction_id &temp_owner)
Definition: item.h:2023
void set_owner(const faction_id &new_owner)
Definition: item.h:2029
Definition: npc.h:744
int rl_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:519
static constexpr int MAX_VIEW_DISTANCE
static const activity_id ACT_PICKUP("ACT_PICKUP")
static const std::string has_thievery_witness("has_thievery_witness")
@ NPCATT_NULL
Definition: npc.h:81
@ NPCATT_RECOVER_GOODS
Definition: npc.h:100

References ACT_PICKUP, c, g, get_owner(), get_player_character(), has_thievery_witness(), string_id< T >::is_null(), is_owned_by(), MAX_VIEW_DISTANCE, NPCATT_NULL, NPCATT_RECOVER_GOODS, owner, Character::pos(), random_entry(), rl_dist(), set_old_owner(), and set_owner().

Referenced by on_pickup(), on_wear(), and on_wield().

◆ has_any_flag()

template<typename Container , typename T = std::decay_t<decltype( *std::declval<const Container &>().begin() )>>
bool item::has_any_flag ( const Container &  flags) const
inline

Definition at line 1408 of file item.h.

1408 {
1409 return std::any_of( flags.begin(), flags.end(), [&]( const T & flag ) {
1410 return has_flag( flag );
1411 } );
1412 }

Referenced by Character::can_eat(), and Character::consume_effects().

◆ has_clothing_mod()

bool item::has_clothing_mod ( ) const

Definition at line 10133 of file item.cpp.

10134{
10135 for( const clothing_mod &cm : clothing_mods::get_all() ) {
10136 if( has_own_flag( cm.flag ) ) {
10137 return true;
10138 }
10139 }
10140 return false;
10141}
const std::vector< clothing_mod > & get_all()

References clothing_mods::get_all(), and has_own_flag().

Referenced by tname().

◆ has_effect_when_carried()

bool item::has_effect_when_carried ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is carried?

Definition at line 9757 of file item.cpp.

9758{
9759 if( !type->artifact ) {
9760 return false;
9761 }
9762 const std::vector<art_effect_passive> &ec = type->artifact->effects_carried;
9763 if( std::find( ec.begin(), ec.end(), effect ) != ec.end() ) {
9764 return true;
9765 }
9766 for( const item *i : contents.all_items_top() ) {
9767 if( i->has_effect_when_carried( effect ) ) {
9768 return true;
9769 }
9770 }
9771 return false;
9772}
Definition: effect.h:161
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
cata::value_ptr< islot_artifact > artifact
Definition: itype.h:866

References item_contents::all_items_top(), itype::artifact, contents, detail::find(), and type.

Referenced by Character::hardcoded_effects(), and Character::has_artifact_with().

◆ has_effect_when_wielded()

bool item::has_effect_when_wielded ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is wielded?

Definition at line 9739 of file item.cpp.

9740{
9741 if( !type->artifact ) {
9742 return false;
9743 }
9744 const std::vector<art_effect_passive> &ew = type->artifact->effects_wielded;
9745 return std::find( ew.begin(), ew.end(), effect ) != ew.end();
9746}

References itype::artifact, detail::find(), and type.

Referenced by Character::hardcoded_effects(), and Character::has_artifact_with().

◆ has_effect_when_worn()

bool item::has_effect_when_worn ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is worn?

Definition at line 9748 of file item.cpp.

9749{
9750 if( !type->artifact ) {
9751 return false;
9752 }
9753 const std::vector<art_effect_passive> &ew = type->artifact->effects_worn;
9754 return std::find( ew.begin(), ew.end(), effect ) != ew.end();
9755}

References itype::artifact, detail::find(), and type.

◆ has_explosion_data()

bool item::has_explosion_data ( ) const

Definition at line 6826 of file item.cpp.

6827{
6828 return is_fuel() ? type->fuel->has_explode_data : false;
6829}

References itype::fuel, is_fuel(), and type.

Referenced by vehicle::explode_fuel().

◆ has_fault()

bool item::has_fault ( const fault_id fault) const

Does this item have the specified fault.

Definition at line 5293 of file item.cpp.

5294{
5295 return faults.count( fault );
5296}
Definition: fault.h:29

References faults.

Referenced by install_bionic_actor::can_use(), color_in_inventory(), bionic_install_preset::get_denial(), bionic_install_surgeon_preset::get_denial(), ranged::handle_gun_damage(), bionic_sterilize_preset::is_shown(), and tname().

◆ has_flag() [1/2]

bool item::has_flag ( const flag_str_id flag) const

Definition at line 5327 of file item.cpp.

5328{
5329 return has_flag( flag.str() );
5330}

References has_flag(), and string_id< T >::str().

◆ has_flag() [2/2]

bool item::has_flag ( const std::string &  flag) const

Definition at line 5303 of file item.cpp.

5304{
5305 bool ret = false;
5306
5307 if( json_flag::get( f ).inherit() ) {
5308 for( const item *e : is_gun() ? gunmods() : toolmods() ) {
5309 // gunmods fired separately do not contribute to base gun flags
5310 if( !e->is_gun() && e->has_flag( f ) ) {
5311 return true;
5312 }
5313 }
5314 }
5315
5316 // other item type flags
5317 ret = type->has_flag( f );
5318 if( ret ) {
5319 return ret;
5320 }
5321
5322 // now check for item specific flags
5323 ret = has_own_flag( f );
5324 return ret;
5325}
bool has_flag(const std::string &flag) const
Definition: itype.cpp:146

References json_flag::get(), gunmods(), itype::has_flag(), has_own_flag(), is_gun(), cata::hash64_detail::ret, toolmods(), and type.

Referenced by Character::activate_bionic(), map::add_item(), map::add_item_or_charges(), monexamine::add_leash(), Character::all_items_with_flag(), Character::allergy_type(), npc::alt_attack(), ammo_consume(), ammo_remaining(), ammo_required(), ammo_set(), amount_of_internal(), Character::armor_absorb(), armor_fit_info(), armor_info(), iexamine::autodoc(), autodoc_internal(), basic_info(), mattack::bio_op_disarm(), iuse::blech(), Character::block_hit(), blocking_ability(), Character::burn_fuel(), butcher_time_to_cut(), butchery_drops_harvest(), calc_rot(), iuse::camera(), item_funcs::can_be_unloaded(), Character::can_consume(), can_do_activity_there(), Character::can_eat(), Character::can_feed_furnace_with(), behavior::character_oracle_t::can_make_fire(), repair_item_actor::can_repair_target(), can_revive(), Character::can_swap(), Character::can_takeoff(), Character::can_unwield(), Character::can_use_heal_item(), Character::can_wear(), Character::can_wield(), iuse::capture_monster_act(), iuse::capture_monster_veh(), cast_spell(), check_litcig(), anonymous_namespace{armor_layers.cpp}::clothing_flags_description(), anonymous_namespace{armor_layers.cpp}::clothing_layer(), color_in_inventory(), combat_info(), comestible_inventory_preset::comestible_inventory_preset(), complete_craft(), crafting::complete_disassemble(), Character::compute_effective_nutrients(), Character::compute_nutrient_range(), conductive(), consider_butchery(), Character::consume_charges(), game_menus::inv::consume_drink(), Character::consume_effects(), game_menus::inv::consume_food(), Character::consume_med(), Character::consume_remote_fuel(), vehicle::consumption_per_hour(), corpse_volume(), activity_handlers::cracking_do_turn(), recipe::create_byproducts(), Single_item_creator::create_single(), iexamine::cvdmachine(), cycle_action(), damage_melee(), repair_item_actor::default_action(), iexamine::dimensional_portal(), display_name(), aim_activity_actor::do_turn(), draw_bionics_titlebar(), game::dump_stats(), durability_indicator(), Character::eat(), einkpc_download_memory_card(), iuse::einktabletpc(), emit_radio_signal(), final_info(), character_funcs::find_ammo_helper(), find_auto_consume(), find_food_heater(), Character::find_remote_fuel(), findBestGasDiscount(), ranged::fire_gun(), activity_handlers::fish_do_turn(), character_funcs::fmt_wielded_weapon(), food_info(), inventory::form_from_map(), Character::fun_for(), activity_handlers::game_do_turn(), character_funcs::get_book_fun_for(), activatable_inventory_preset::get_denial(), bionic_sterilize_preset::get_denial(), get_encumber_when_containing(), ranged::get_fastest_sight(), Character::get_fuel_available(), get_layer(), zone_manager::get_near_zone_type_for_item(), get_sizing(), ranged::get_str_draw_penalty(), getlight_emit(), give_item_to(), goes_bad(), gun_info(), iuse::gun_repair(), gun_type(), gunmod_info(), ranged::gunmode_checks_common(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), ranged::handle_gun_damage(), Character::handle_melee_wear(), handle_problematic_pickup(), Character::has_enough_charges(), has_flag(), Character::has_item_with_flag(), Character::head_cloth_encumbrance(), iuse_transform::info(), inherit_flags(), npc_trading::init_buying(), init_memory_card_with_random_stuff(), target_ui::init_window_and_input(), monexamine::insert_battery(), is_ammo_belt(), is_armor(), is_corpse(), is_dangerous(), advanced_inventory_pane::is_filtered(), is_filthy(), is_firearm(), character_funcs::is_fun_to_read(), is_gunmod_compatible(), is_irremovable(), vehicle::is_perpetual_type(), is_pet_armor(), is_power_armor(), is_reloadable(), is_salvageable(), bionic_uninstall_preset::is_shown(), is_two_handed(), is_unarmed_weapon(), ma_requirements::is_valid_character(), ma_requirements::is_valid_weapon(), is_worn_only_with(), item(), Character::item_reload_cost(), mdeath::jabberwock(), layer_item(), magazine_info(), item_action_generator::map_actions_to_items(), Character::meets_stat_requirements(), Character::melee_attack(), melee_skill(), Character::melee_special_effects(), npc_ai::melee_value(), mine_activity(), Item_modifier::modify(), Character::modify_morale(), avatar_action::move(), game_menus::inv::multiwash(), Character::mutation_effect(), iexamine::nanofab(), needs_processing(), iuse::note_bionics(), on_wear(), on_wield(), iuse::pack_cbm(), Character::passive_power_gen(), monexamine::pet_menu(), avatar_action::plthrow(), iuse::poison(), item_category::priority_zone(), process_extinguish(), process_internal(), Character::process_items(), process_litcig(), process_tool(), process_UPS(), process_vehicle_items(), vehicle_part::properties_to_item(), mattack::pull_metal_weapon(), activity_handlers::pulp_do_turn(), item_reload_option::qty(), iuse::radio_mod(), iuse::radiocar(), iuse::radiocontrol(), rate_food(), rcdrive(), reach_range(), ready_to_revive(), reinforceable(), avatar_action::reload(), reload(), activity_handlers::reload_finish(), remove_ammo(), remove_radio_mod(), repair_item_actor::repair(), repaired_with(), game::revive_corpse(), iexamine::safe(), character_funcs::select_ammo(), set_relative_rot(), player_morale::set_worn(), sight_dispersion(), iexamine::sign(), smoker_load_food(), map::spawn_item(), activity_handlers::spellcasting_finish(), activity_handlers::start_fire_do_turn(), starting_clothes(), starting_inv(), ranged::str_draw_damage_modifier(), ranged::str_draw_dispersion_modifier(), ranged::str_draw_range_modifier(), Character::suffer_from_sunburn(), ranged::throw_item(), tname(), tool_info(), iuse::toolmod_attach(), iuse::towel_common(), type_name(), Character::unarmed_attack(), units_remaining(), avatar_funcs::unload_item(), charger_tile::update_internal(), iuse_transform::use(), set_transform_iuse::use(), unpack_actor::use(), cast_spell_actor::use(), Character::use_charges(), iexamine::use_furn_fake_item(), avatar_action::use_item(), avatar_funcs::use_item(), vehicle::use_washing_machine(), npc::value(), volume(), martialart::weapon_valid(), npc::wear_if_wanted(), Character::wear_item(), iuse::weather_tool(), weight(), weather_effect::wet_player(), npc::will_accept_from_player(), and Character::will_eat().

◆ has_infinite_charges()

bool item::has_infinite_charges ( ) const

Definition at line 9961 of file item.cpp.

9962{
9963 return charges == INFINITE_CHARGES;
9964}

References charges, and INFINITE_CHARGES.

Referenced by display_name(), liquid_handler::get_liquid_target(), mod_charges(), and Character::will_eat().

◆ has_label()

bool item::has_label ( ) const

Returns true if item has "item_label" itemvar.

Definition at line 9947 of file item.cpp.

9948{
9949 return has_var( "item_label" );
9950}

References has_var().

Referenced by label().

◆ has_own_flag()

bool item::has_own_flag ( const std::string &  flag) const

Checks whether item itself has given flag (doesn't check item type or gunmods).

Essentially get_flags().count(f). Works faster than has_flag

Definition at line 5298 of file item.cpp.

5299{
5300 return item_tags.count( f );
5301}
size_type count(const T &t) const
Definition: flat_set.h:141

References cata::flat_set< T, Compare, Data >::count(), and item_tags.

Referenced by Character::can_eat(), Character::can_wear(), color_in_inventory(), final_info(), has_clothing_mod(), has_flag(), mod_last_rot_check(), on_drop(), tname(), update_clothing_mod_val(), and sew_advanced_actor::use().

◆ has_property()

bool item::has_property ( const std::string &  prop) const

Definition at line 5358 of file item.cpp.

5359{
5360 return type->properties.find( prop ) != type->properties.end();
5361}

References itype::properties, and type.

Referenced by iuse::capture_monster_act(), and ranged::throw_item().

◆ has_rotten_away()

bool item::has_rotten_away ( ) const

Whether the item has enough rot that it should get removed.

Regular shelf life perishable foods rot away completely at 2x shelf life. Corpses last 10 days

Returns
true if the item has enough rot to be removed, false otherwise.

Definition at line 8795 of file item.cpp.

8796{
8797 if( is_corpse() && !can_revive() ) {
8798 return get_rot() > 10_days;
8799 } else {
8800 return is_food() && get_relative_rot() > 2.0;
8801 }
8802}
time_duration get_rot() const
Definition: item.h:861

References can_revive(), get_relative_rot(), get_rot(), is_corpse(), and is_food().

Referenced by process_rot().

◆ has_technique()

bool item::has_technique ( const matec_id tech) const

Whether the item supports a specific martial art technique (either through its type, or through its individual techniques).

Definition at line 5439 of file item.cpp.

5440{
5441 return type->techniques.count( tech ) > 0 || techniques.count( tech ) > 0;
5442}

References techniques, itype::techniques, and type.

Referenced by blocking_ability(), effective_dps(), character_martial_arts::has_technique(), and mdeath::jabberwock().

◆ has_tools_to_continue()

bool item::has_tools_to_continue ( ) const

Definition at line 10106 of file item.cpp.

10107{
10108 assert( craft_data_ );
10109 return craft_data_->tools_to_continue;
10110}

References craft_data_.

◆ has_use()

bool item::has_use ( ) const

Returns true if the item has any use function.

Definition at line 7943 of file item.cpp.

7944{
7945 return type->has_use();
7946}
bool has_use() const
Definition: itype.cpp:141

References itype::has_use(), and type.

◆ has_var()

◆ ideal_ranged_dps()

double item::ideal_ranged_dps ( const Character who,
gun_mode mode 
) const

Definition at line 2072 of file npcmove.cpp.

2073{
2074 if( !is_gun() ) {
2075 return 0;
2076 }
2078 if( ammo_current() ) {
2079 itype_id ammo = ammo_current();
2080 gun_damage.add( ammo->ammo->damage );
2081 } else if( ammo_default() ) {
2082 itype_id ammo = ammo_default();
2083 gun_damage.add( ammo->ammo->damage );
2084 }
2085 float damage_factor = gun_damage.total_damage();
2086 damage_factor *= mode.qty;
2087
2088 int move_cost = ranged::time_to_attack( who, *this, item_location() );
2089 if( ammo_remaining() == 0 ) {
2090 int reload_cost = get_reload_time() + who.encumb( bp_hand_l ) + who.encumb( bp_hand_r );
2091 // HACK: Doesn't check how much ammo they'll actually get from the reload. Because we don't know.
2092 // DPS is less impacted the larger the magazine being swapped.
2093 reload_cost /= magazine_integral() ? 1 : ammo_capacity() / mode.qty;
2094 move_cost += reload_cost;
2095 }
2096 std::vector<ranged::aim_type> aim_types = ranged::get_aim_types( who, *this );
2097 auto regular = std::find_if( aim_types.begin(),
2098 aim_types.end(), []( ranged::aim_type at ) {
2099 return at.action == std::string( "AIMED_SHOT" );
2100 } );
2101 if( regular == aim_types.end() ) {
2102 debugmsg( "Could not find REGULAR aim type for gun %s", tname() );
2103 return 0;
2104 }
2105 move_cost += ranged::gun_engagement_moves( who, *this, ( *regular ).threshold );
2106
2107 double dps = damage_factor / ( move_cost / 100.0f );
2108
2109 return dps;
2110}
static int move_cost(const item &it, const tripoint &src, const tripoint &dest)
int qty
burst size for is_gun() firearms, or melee range for is_melee() weapons
Definition: gun_mode.h:21
A lightweight handle to an item independent of it's location Unlike a raw pointer can be (de-)seriali...
Definition: item_location.h:23
int get_reload_time() const
Returns the reload time of the gun.
Definition: item.cpp:6528
void regular(const queued_explosion &qe)
Definition: explosion.cpp:1466
int time_to_attack(const Character &p, const item &firing, const item_location loc)
Calculates time taken to fire gun.
Definition: ranged.cpp:1737
void add(const damage_instance &added_di)
Definition: damage.cpp:93

References damage_instance::add(), itype::ammo, ammo_capacity(), ammo_current(), ammo_default(), ammo_remaining(), bp_hand_l, bp_hand_r, debugmsg, dps(), Character::encumb(), ranged::get_aim_types(), get_reload_time(), gun_damage(), ranged::gun_engagement_moves(), is_gun(), magazine_integral(), move_cost(), gun_mode::qty, explosion_handler::explosion_funcs::regular(), ranged::time_to_attack(), tname(), and damage_instance::total_damage().

Referenced by npc::check_or_use_weapon_cbm(), and npc_ai::gun_value().

◆ in_container()

item item::in_container ( const itype_id container_type) const

Definition at line 846 of file item.cpp.

847{
848 if( !cont.is_null() ) {
849 item ret( cont, birthday() );
850 ret.put_in( *this );
851 if( made_of( LIQUID ) && ret.is_container() ) {
852 // Note: we can't use any of the normal container functions as they check the
853 // container being suitable (seals, watertight etc.)
854 ret.contents.back().charges = charges_per_volume( ret.get_container_capacity() );
855 }
856
857 ret.invlet = invlet;
858 return ret;
859 } else {
860 return *this;
861 }
862}
char invlet
Definition: item.h:2240

References birthday(), charges_per_volume(), invlet, string_id< T >::is_null(), LIQUID, made_of(), and cata::hash64_detail::ret.

Referenced by in_its_container().

◆ in_its_container()

item item::in_its_container ( ) const

Returns this item into its default container.

If it does not have a default container, returns this. It's intended to be used like

newitem = newitem.in_its_container();

Definition at line 841 of file item.cpp.

842{
843 return in_container( type->default_container.value_or( itype_id::NULL_ID() ) );
844}
item in_container(const itype_id &container_type) const
Definition: item.cpp:846
std::optional< itype_id > default_container
Definition: itype.h:912

References itype::default_container, in_container(), string_id< itype >::NULL_ID(), and type.

Referenced by defense_game::caravan(), crafting::complete_disassemble(), Single_item_creator::create_single(), map::spawn_an_item(), starting_inv(), and debug_menu::wishitem().

◆ inc_damage() [1/2]

bool item::inc_damage ( )

same as other inc_damage, but uses DT_NULL as damage type.

Definition at line 6258 of file item.cpp.

6259{
6260 return inc_damage( DT_NULL );
6261}
bool inc_damage()
same as other inc_damage, but uses DT_NULL as damage type.
Definition: item.cpp:6258

References DT_NULL, and inc_damage().

Referenced by inc_damage(), and process_blackpowder_fouling().

◆ inc_damage() [2/2]

bool item::inc_damage ( damage_type  dt)

Increment item damage by itype::damage_scale constrained by max_damage.

Parameters
dttype of damage which may be passed to on_damage callback
Returns
whether item should be destroyed

Definition at line 6253 of file item.cpp.

6254{
6255 return mod_damage( itype::damage_scale, dt );
6256}
bool mod_damage(int qty, damage_type dt)
Apply damage to const itemrained by min_damage and max_damage.
Definition: item.cpp:6226
static constexpr int damage_scale
Definition: itype.h:1008

References itype::damage_scale, and mod_damage().

Referenced by iuse::blood_draw(), damage_item(), iuse::firecracker_pack_act(), activity_handlers::gunmod_add_finish(), ranged::handle_gun_damage(), Character::handle_melee_wear(), activity_handlers::lockpicking_finish(), and vehicle::operate_scoop().

◆ info() [1/4]

std::vector< iteminfo > item::info ( ) const

Return all the information about the item and its type as a vector.

This includes the different properties of the itype (if they are visible to the player).

Parameters
partscontrols which parts of the iteminfo to return.
batchThe batch crafting number to multiply data by
Returns
The properties (encapsulated into iteminfo) are added to this vector, the vector can be used to compare them to properties of another item.

Definition at line 3971 of file item.cpp.

3972{
3974}
static const iteminfo_query no_conditions

References info(), iteminfo_query::no_conditions, and TEMP_NORMAL.

Referenced by advanced_inventory::action_examine(), ammo_info(), animal_armor_info(), armor_fit_info(), armor_info(), armor_protection_info(), basic_info(), battery_info(), bionic_info(), book_info(), combat_info(), game_menus::inv::compare(), component_info(), container_info(), contents_info(), disassembly_info(), final_info(), food_info(), gun_info(), gunmod_info(), info(), info_string(), game::list_items(), magazine_info(), med_info(), qualities_info(), wish_item_callback::refresh(), repair_info(), examine_item_menu::run(), trading_window::show_item_data(), and tool_info().

◆ info() [2/4]

std::vector< iteminfo > item::info ( const iteminfo_query parts,
int  batch,
temperature_flag  temperature 
) const

Definition at line 3986 of file item.cpp.

3988{
3989 const bool debug = g != nullptr && debug_mode;
3990
3991 // TODO: Use reference properly
3992 const iteminfo_query *parts = &parts_ref;
3993 std::vector<iteminfo> info;
3994
3995 if( !is_null() ) {
3996 basic_info( info, parts, batch, debug );
3997 }
3998
3999 const item *med_item = nullptr;
4000 if( is_medication() ) {
4001 med_item = this;
4002 } else if( is_med_container() ) {
4003 med_item = &contents.front();
4004 }
4005 if( med_item != nullptr ) {
4006 med_info( med_item, info, parts, batch, debug );
4007 }
4008
4009 if( const item *food_item = get_food() ) {
4010 food_info( food_item, info, parts, batch, debug, temperature );
4011 }
4012
4013 container_info( info, parts, batch, debug );
4014 contents_info( info, parts, batch, debug );
4015 combat_info( info, parts, batch, debug );
4016
4017 magazine_info( info, parts, batch, debug );
4018 ammo_info( info, parts, batch, debug );
4019
4020 const item *gun = nullptr;
4021 if( is_gun() ) {
4022 gun = this;
4023 const gun_mode aux = gun_current_mode();
4024 // if we have an active auxiliary gunmod display stats for this instead
4025 if( aux && aux->is_gunmod() && aux->is_gun() &&
4027 gun = &*aux;
4028 info.emplace_back( "DESCRIPTION",
4029 string_format( _( "Stats of the active <info>gunmod (%s)</info> "
4030 "are shown." ), gun->tname() ) );
4031 }
4032 }
4033 if( gun != nullptr ) {
4034 gun_info( gun, info, parts, batch, debug );
4035 }
4036
4037 gunmod_info( info, parts, batch, debug );
4038 armor_info( info, parts, batch, debug );
4039 animal_armor_info( info, parts, batch, debug );
4040 book_info( info, parts, batch, debug );
4041 battery_info( info, parts, batch, debug );
4042 tool_info( info, parts, batch, debug );
4043 component_info( info, parts, batch, debug );
4044 qualities_info( info, parts, batch, debug );
4045
4046 // Uses for item (bandaging quality, holster capacity, grenade activation)
4048 for( const std::pair<const std::string, use_function> &method : type->use_methods ) {
4050 method.second.dump_info( *this, info );
4051 }
4052 }
4053
4054 repair_info( info, parts, batch, debug );
4055 disassembly_info( info, parts, batch, debug );
4056
4057 final_info( info, parts_ref, batch, debug );
4058
4059 if( !info.empty() && info.back().sName == "--" ) {
4060 info.pop_back();
4061 }
4062
4063 return info;
4064}
void gunmod_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2380
gun_mode gun_current_mode() const
Get the current mode for this gun (or an invalid mode if item is not a gun)
Definition: item.cpp:7898
void contents_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3543
void animal_armor_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2715
void med_info(const item *med_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1641
void disassembly_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3174
void combat_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3398
bool is_med_container() const
Definition: item.cpp:6615
void qualities_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3228
void gun_info(const item *mod, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2017
void component_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3129
void repair_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3153
void magazine_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1881
void food_info(const item *food_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug, temperature_flag temperature) const
Definition: item.cpp:1670
void armor_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2532
void battery_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3062
void ammo_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1904
void basic_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1458
void final_info(std::vector< iteminfo > &info, const iteminfo_query &parts, int batch, bool debug) const
Definition: item.cpp:3626
void book_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2897
void tool_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3081
void container_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3034
@ DESCRIPTION_AUX_GUNMOD_HEADER

References _, ammo_info(), animal_armor_info(), armor_info(), basic_info(), battery_info(), book_info(), combat_info(), component_info(), container_info(), contents, contents_info(), debug, debug_mode, DESCRIPTION_AUX_GUNMOD_HEADER, DESCRIPTION_USE_METHODS, disassembly_info(), final_info(), food_info(), item_contents::front(), g, get_food(), gun_current_mode(), gun_info(), gunmod_info(), info(), insert_separation_line(), is_gun(), is_gunmod(), is_med_container(), is_medication(), is_null(), magazine_info(), med_info(), qualities_info(), repair_info(), string_format(), iteminfo_query::test(), tname(), tool_info(), type, and itype::use_methods.

◆ info() [3/4]

std::vector< iteminfo > item::info ( int  batch) const

Definition at line 3976 of file item.cpp.

References info(), iteminfo_query::no_conditions, and TEMP_NORMAL.

◆ info() [4/4]

std::vector< iteminfo > item::info ( temperature_flag  temperature) const

Definition at line 3981 of file item.cpp.

3982{
3983 return info( iteminfo_query::all, 1, temperature );
3984}
static const iteminfo_query all

References iteminfo_query::all, and info().

◆ info_string() [1/2]

std::string item::info_string ( ) const

As info, but as a string rather than a vector of properties.

Definition at line 4066 of file item.cpp.

4067{
4068 return info_string( iteminfo_query::all, 1 );
4069}

References iteminfo_query::all, and info_string().

Referenced by battery_info(), colorized_item_description(), draw_caravan_items(), and info_string().

◆ info_string() [2/2]

std::string item::info_string ( const iteminfo_query parts,
int  batch = 1,
temperature_flag  temperature = temperature_flag::TEMP_NORMAL 
) const

Definition at line 4071 of file item.cpp.

4073{
4074 std::vector<iteminfo> item_info = info( parts, batch, temperature );
4075 return format_item_info( item_info, {} );
4076}
std::string format_item_info(const std::vector< iteminfo > &item_display, const std::vector< iteminfo > &item_compare)
Definition: output.cpp:854

References format_item_info(), and info().

◆ inherit_flags() [1/2]

void item::inherit_flags ( const item parent,
const recipe making 
)

Inherit applicable flags from the given parent item.

Parameters
parentItem to inherit from

Definition at line 984 of file crafting.cpp.

985{
986 // default behavior is to resize the clothing, which happens elsewhere
987 if( making.has_flag( flag_NO_RESIZE ) ) {
988 //If item is crafted from poor-fit components, the result is poorly fitted too
989 if( parent.has_flag( flag_VARSIZE ) ) {
991 }
992 //If item is crafted from perfect-fit components, the result is perfectly fitted too
993 if( parent.has_flag( flag_FIT ) ) {
995 }
996 }
997 for( const std::string &f : parent.item_tags ) {
998 if( json_flag::get( f ).craft_inherit() ) {
999 set_flag( f );
1000 }
1001 }
1002 for( const std::string &f : parent.type->get_flags() ) {
1003 if( json_flag::get( f ).craft_inherit() ) {
1004 set_flag( f );
1005 }
1006 }
1007 if( parent.has_flag( flag_HIDDEN_POISON ) ) {
1008 poison = parent.poison;
1009 }
1010}
int poison
Definition: item.h:2208
bool has_flag(const std::string &flag_name) const
Definition: recipe.cpp:92
static const std::string flag_NO_RESIZE("NO_RESIZE")
static const std::string flag_HIDDEN_POISON("HIDDEN_POISON")
static const std::string flag_FIT("FIT")
static const std::string flag_VARSIZE("VARSIZE")

References flag_FIT(), flag_HIDDEN_POISON(), flag_NO_RESIZE(), flag_VARSIZE(), json_flag::get(), itype::get_flags(), has_flag(), recipe::has_flag(), item_tags, poison, set_flag(), type, and unset_flag().

Referenced by complete_craft(), and inherit_flags().

◆ inherit_flags() [2/2]

void item::inherit_flags ( const std::list< item > &  parents,
const recipe making 
)

Inherit applicable flags from the given list of parent items.

Parameters
parentsItems to inherit from

Definition at line 1012 of file crafting.cpp.

1013{
1014 for( const item &parent : parents ) {
1015 inherit_flags( parent, making );
1016 }
1017}
void inherit_flags(const item &parent, const recipe &making)
Inherit applicable flags from the given parent item.
Definition: crafting.cpp:984
std::vector< item * > parents(const item &it)
Returns vector of parent containers (if any) starting with the innermost.
Definition: visitable.cpp:73

References inherit_flags(), and visitable< item >::parents().

◆ io()

template<typename Archive >
void item::io ( Archive &  archive)

Definition at line 2187 of file savegame_json.cpp.

2188{
2189
2190 itype_id orig; // original ID as loaded from JSON
2191 const auto load_type = [&]( const std::string & id ) {
2192 orig = itype_id( id );
2193 convert( item_controller->migrate_id( orig ) );
2194 };
2195
2196 const auto load_curammo = [this]( const std::string & id ) {
2197 curammo = &*item_controller->migrate_id( itype_id( id ) );
2198 };
2199 const auto load_corpse = [this]( const std::string & id ) {
2200 if( itype_id( id ).is_null() ) {
2201 // backwards compatibility, nullptr should not be stored at all
2202 corpse = nullptr;
2203 } else {
2204 corpse = &mtype_id( id ).obj();
2205 }
2206 };
2207 archive.template io<const itype>( "typeid", type, load_type, []( const itype & i ) {
2208 return i.get_id().str();
2209 }, io::required_tag() );
2210
2211 // normalize legacy saves to always have charges >= 0
2212 archive.io( "charges", charges, 0 );
2213 charges = std::max( charges, 0 );
2214
2215 archive.io( "energy", energy, 0_J );
2216
2217 archive.io( "burnt", burnt, 0 );
2218 archive.io( "poison", poison, 0 );
2219 archive.io( "frequency", frequency, 0 );
2220 archive.io( "snip_id", snip_id, snippet_id::NULL_ID() );
2221 // NB! field is named `irridation` in legacy files
2222 archive.io( "irridation", irradiation, 0 );
2223 archive.io( "bday", bday, calendar::start_of_cataclysm );
2224 archive.io( "mission_id", mission_id, -1 );
2225 archive.io( "player_id", player_id, -1 );
2226 archive.io( "item_vars", item_vars, io::empty_default_tag() );
2227 // TODO: change default to empty string
2228 archive.io( "name", corpse_name, std::string() );
2229 archive.io( "owner", owner, owner.NULL_ID() );
2230 archive.io( "old_owner", old_owner, old_owner.NULL_ID() );
2231 archive.io( "invlet", invlet, '\0' );
2232 archive.io( "damaged", damage_, 0 );
2233 archive.io( "active", active, false );
2234 archive.io( "is_favorite", is_favorite, false );
2235 archive.io( "item_counter", item_counter, static_cast<decltype( item_counter )>( 0 ) );
2236 archive.io( "rot", rot, 0_turns );
2237 archive.io( "last_rot_check", last_rot_check, calendar::start_of_cataclysm );
2238 archive.io( "techniques", techniques, io::empty_default_tag() );
2239 archive.io( "faults", faults, io::empty_default_tag() );
2240 archive.io( "item_tags", item_tags, io::empty_default_tag() );
2241 archive.io( "components", components, io::empty_default_tag() );
2242 archive.io( "recipe_charges", recipe_charges, 1 );
2243 archive.template io<const itype>( "curammo", curammo, load_curammo,
2244 []( const itype & i ) {
2245 return i.get_id().str();
2246 } );
2247 archive.template io<const mtype>( "corpse", corpse, load_corpse,
2248 []( const mtype & i ) {
2249 return i.id.str();
2250 } );
2251 archive.io( "craft_data", craft_data_, decltype( craft_data_ )() );
2252 archive.io( "light", light.luminance, nolight.luminance );
2253 archive.io( "light_width", light.width, nolight.width );
2254 archive.io( "light_dir", light.direction, nolight.direction );
2255
2256 static const cata::value_ptr<relic> null_relic_ptr = nullptr;
2257 archive.io( "relic_data", relic_data, null_relic_ptr );
2258
2259 archive.io( "drop_token", drop_token, decltype( drop_token )() );
2260
2261 item_controller->migrate_item( orig, *this );
2262
2263 if( !Archive::is_input::value ) {
2264 return;
2265 }
2266 /* Loading has finished, following code is to ensure consistency and fixes bugs in saves. */
2267
2269
2270 double float_damage = 0;
2271 if( archive.read( "damage", float_damage ) ) {
2272 damage_ = std::min( std::max( min_damage(),
2273 static_cast<int>( float_damage * itype::damage_scale ) ),
2274 max_damage() );
2275 }
2276
2277 int note = 0;
2278 const bool note_read = archive.read( "note", note );
2279
2280 // Old saves used to only contain one of those values (stored under "poison"), it would be
2281 // loaded into a union of those members. Now they are separate members and must be set separately.
2282 if( poison != 0 && note == 0 && !type->snippet_category.empty() ) {
2283 std::swap( note, poison );
2284 }
2285 if( poison != 0 && frequency == 0 && ( typeId() == itype_radio_on || typeId() == itype_radio ) ) {
2287 }
2288 if( poison != 0 && irradiation == 0 && typeId() == itype_rad_badge ) {
2290 }
2291
2292 // erase all invalid flags (not defined in flags.json), display warning about invalid flags
2293 erase_if( item_tags, [&]( const std::string & f ) {
2294 if( !json_flag::get( f ).id.is_valid() ) {
2295 debugmsg( "item of type '%s' was loaded with undefined flag '%s'.", typeId().c_str(), f );
2296 return true;
2297 } else {
2298 return false;
2299 }
2300 } );
2301
2302 if( note_read ) {
2304 } else {
2305 std::optional<std::string> snip;
2306 if( archive.read( "snippet_id", snip ) && snip ) {
2307 snip_id = snippet_id( snip.value() );
2308 }
2309 }
2310
2311 // Compatibility for item type changes: for example soap changed from being a generic item
2312 // (item::charges -1 or 0 or anything else) to comestible (and thereby counted by charges),
2313 // old saves still have invalid charges, this fixes the charges value to the default charges.
2314 if( count_by_charges() && charges <= 0 ) {
2316 }
2317 if( is_food() ) {
2318 active = true;
2319 }
2320 if( !active && item_tags.count( "WET" ) > 0 ) {
2321 // Some wet items from legacy saves may be inactive
2322 active = true;
2323 }
2324 std::string mode;
2325 if( archive.read( "mode", mode ) ) {
2326 // only for backward compatibility (nowadays mode is stored in item_vars)
2327 gun_set_mode( gun_mode_id( mode ) );
2328 }
2329
2330 // Books without any chapters don't need to store a remaining-chapters
2331 // counter, it will always be 0 and it prevents proper stacking.
2332 if( get_chapters() == 0 ) {
2333 for( auto it = item_vars.begin(); it != item_vars.end(); ) {
2334 if( it->first.compare( 0, 19, "remaining-chapters-" ) == 0 ) {
2335 item_vars.erase( it++ );
2336 } else {
2337 ++it;
2338 }
2339 }
2340 }
2341
2342 // Remove stored translated gerund in favor of storing the inscription tool type
2343 item_vars.erase( "item_label_type" );
2344 item_vars.erase( "item_note_type" );
2345
2346 // Activate corpses from old saves
2347 if( is_corpse() && !active ) {
2348 active = true;
2349 }
2350
2351 if( charges != 0 && !type->can_have_charges() ) {
2352 // Types that are known to have charges, but should not have them.
2353 // We fix it here, but it's expected from bugged saves and does not require a message.
2354 if( charge_removal_blacklist::get().count( type->get_id() ) == 0 ) {
2355 debugmsg( "Item %s was loaded with charges, but can not have any!", type->get_id() );
2356 }
2357 charges = 0;
2358 }
2359
2360 // Relic check. Kinda late, but that's how relics have to be
2361 if( relic_data ) {
2362 relic_data->check();
2363 }
2364}
bool erase_if(Col &set, Pred predicate)
Erases elements from a set that match given predicate function.
Definition: cata_utility.h:237
int player_id
Definition: item.h:2214
int mission_id
Definition: item.h:2213
int frequency
Definition: item.h:2209
int recipe_charges
Definition: item.h:2206
snippet_id migrate_hash_to_id(int hash)
Used only for legacy compatibility.
light_emission nolight
Definition: item.cpp:312
void swap(colony< element_type, element_allocator_type, element_skipfield_type > &a, colony< element_type, element_allocator_type, element_skipfield_type > &b) COLONY_NOEXCEPT_SWAP(element_allocator_type)
Swaps colony A's contents with that of colony B.
Definition: colony.h:3496
const std::set< itype_id > & get()
static void load_legacy_craft_data(io::JsonObjectInputArchive &archive, T &value)
static const itype_id itype_radio("radio")
static const itype_id itype_radio_on("radio_on")
static const itype_id itype_rad_badge("rad_badge")
Tag that indicates the value of the io is some kind of container and its default value is to be empty...
Definition: cata_io.h:105
Tag that indicates the value is required and must exists in the JSON data.
Definition: cata_io.h:110
bool can_have_charges() const
Definition: itype.cpp:219
mtype_id id
Definition: mtype.h:240
string_id< translation > snippet_id
Definition: type_id.h:205

References active, bday, burnt, itype::can_have_charges(), charges, components, convert(), corpse, corpse_name, count(), cata::flat_set< T, Compare, Data >::count(), count_by_charges(), craft_data_, curammo, damage_, itype::damage_scale, debugmsg, light_emission::direction, energy, erase_if(), faults, frequency, charge_removal_blacklist::get(), json_flag::get(), get_chapters(), itype::get_id(), gun_set_mode(), base_camps::id, itype::id, invlet, irradiation, is_corpse(), is_favorite, is_food(), item(), item_controller, item_counter, item_tags, item_vars, itype_id, itype_rad_badge, itype_radio, itype_radio_on, last_rot_check, light, load_legacy_craft_data(), light_emission::luminance, max_damage(), snippet_library::migrate_hash_to_id(), min_damage(), mission_id, mtype_id, nolight, string_id< translation >::NULL_ID(), string_id< T >::NULL_ID(), old_owner, owner, player_id, poison, recipe_charges, relic_data, snip_id, SNIPPET, itype::snippet_category, calendar::start_of_cataclysm, string_id< T >::str(), cata::swap(), techniques, type, typeId(), and light_emission::width.

Referenced by deserialize(), and serialize().

◆ is_ammo()

◆ is_ammo_belt()

bool item::is_ammo_belt ( ) const

Definition at line 6567 of file item.cpp.

6568{
6569 return is_magazine() && has_flag( flag_MAG_BELT );
6570}
static const std::string flag_MAG_BELT("MAG_BELT")

References flag_MAG_BELT(), has_flag(), and is_magazine().

Referenced by Character::can_reload(), item_reload_option::item_reload_option(), avatar_action::reload(), reload(), and avatar_funcs::unload_item().

◆ is_ammo_container()

◆ is_armor()

◆ is_artifact()

bool item::is_artifact ( ) const

Definition at line 6968 of file item.cpp.

6969{
6970 return !!type->artifact;
6971}

References itype::artifact, and type.

Referenced by game::add_artifact_dreams(), iuse::artifact(), needs_processing(), and process_artifact().

◆ is_bandolier()

bool item::is_bandolier ( ) const

◆ is_battery()

bool item::is_battery ( ) const

Definition at line 6562 of file item.cpp.

6563{
6564 return !!type->battery;
6565}

References itype::battery, and type.

Referenced by battery_info(), display_name(), energy_remaining(), and mod_energy().

◆ is_bionic()

◆ is_book()

◆ is_brewable()

bool item::is_brewable ( ) const

Definition at line 6603 of file item.cpp.

6604{
6605 return !!type->brewable;
6606}

References itype::brewable, and type.

Referenced by brewing_results(), brewing_time(), final_info(), iexamine::fvat_empty(), and iexamine::fvat_full().

◆ is_bucket()

bool item::is_bucket ( ) const

Definition at line 6734 of file item.cpp.

6735{
6736 // That "preserves" part is a hack:
6737 // Currently all non-empty cans are effectively sealed at all times
6738 // Making them buckets would cause weirdness
6739 return type->container &&
6740 type->container->watertight &&
6741 !type->container->seals &&
6742 !type->container->unseals_into;
6743}

References itype::container, and type.

Referenced by can_unload_liquid(), get_remaining_capacity_for_liquid(), is_bucket_nonempty(), is_container_eligible_for_crafting(), is_funnel_container(), pick_one_up(), and iexamine::tree_maple_tapped().

◆ is_bucket_nonempty()

bool item::is_bucket_nonempty ( ) const

◆ is_comestible()

◆ is_container()

◆ is_container_empty()

◆ is_container_full()

bool item::is_container_full ( bool  allow_bucket = false) const

Whether this item has no more free capacity for its current content.

Parameters
allow_bucketAllow filling non-sealable containers

Definition at line 6842 of file item.cpp.

6843{
6844 if( is_container_empty() ) {
6845 return false;
6846 }
6847 return get_remaining_capacity_for_liquid( contents.front(), allow_bucket ) == 0;
6848}

References contents, item_contents::front(), get_remaining_capacity_for_liquid(), and is_container_empty().

Referenced by is_container_eligible_for_crafting(), is_reloadable_helper(), and avatar_action::reload().

◆ is_corpse()

bool item::is_corpse ( ) const

Whether this is a corpse item.

Corpses always have valid monster type (corpse) associated (get_mtype return a non-null pointer) and have been created with make_corpse.

Definition at line 6620 of file item.cpp.

6621{
6622 return corpse != nullptr && has_flag( flag_CORPSE );
6623}

References corpse, flag_CORPSE(), and has_flag().

Referenced by base_volume(), burn(), activity_handlers::butcher_finish(), calc_rot(), can_revive(), color(), color_in_inventory(), component_info(), zone_manager::get_near_zone_type_for_item(), get_shelf_life(), goes_bad(), has_rotten_away(), io(), made_of(), on_damage(), process_internal(), map::process_items_in_vehicle(), processing_speed(), game::revive_corpse(), tname(), volume(), and weight().

◆ is_craft()

◆ is_dangerous()

bool item::is_dangerous ( ) const

Definition at line 9801 of file item.cpp.

9802{
9803 if( has_flag( flag_DANGEROUS ) ) {
9804 return true;
9805 }
9806
9807 // Note: Item should be dangerous regardless of what type of a container is it
9808 // Visitable interface would skip some options
9809 for( const item *it : contents.all_items_top() ) {
9810 if( it->is_dangerous() ) {
9811 return true;
9812 }
9813 }
9814 return false;
9815}
static const std::string flag_DANGEROUS("DANGEROUS")

References item_contents::all_items_top(), contents, flag_DANGEROUS(), and has_flag().

Referenced by give_item_to(), and npc::value().

◆ is_deployable()

bool item::is_deployable ( ) const

Definition at line 6953 of file item.cpp.

6954{
6955 return type->can_use( "deploy_furn" );
6956}

References itype::can_use(), and type.

Referenced by Character::invoke_item().

◆ is_emissive()

bool item::is_emissive ( ) const

Whether the item emits any light at all.

Definition at line 6948 of file item.cpp.

6949{
6950 return light.luminance > 0 || type->light_emission > 0;
6951}

References light, itype::light_emission, light_emission::luminance, and type.

Referenced by submap::load(), map::update_lum(), submap::update_lum_add(), and submap::update_lum_rem().

◆ is_engine()

bool item::is_engine ( ) const

Definition at line 6750 of file item.cpp.

6751{
6752 return !!type->engine;
6753}

References itype::engine, and type.

Referenced by is_faulty(), and tname().

◆ is_faulty()

bool item::is_faulty ( ) const

Definition at line 6770 of file item.cpp.

6771{
6772 return is_engine() ? !faults.empty() : false;
6773}
bool is_engine() const
Definition: item.cpp:6750

References faults, and is_engine().

Referenced by clear_faults(), and vehicle_part::name().

◆ is_filthy()

bool item::is_filthy ( ) const

Marks the item as filthy, so characters with squeamish trait can't wear it.

Definition at line 9981 of file item.cpp.

9982{
9983 return has_flag( flag_FILTHY ) && ( get_option<bool>( "FILTHY_MORALE" ) ||
9985}
static const std::string flag_FILTHY("FILTHY")
static const trait_id trait_SQUEAMISH("SQUEAMISH")

References flag_FILTHY(), get_avatar(), has_flag(), Character::has_trait(), and trait_SQUEAMISH.

Referenced by Character::can_wear(), color_in_inventory(), crafting::complete_disassemble(), salvage_actor::cut_up(), repair_item_actor::handle_components(), item_category::priority_zone(), activity_handlers::reload_finish(), tname(), avatar_funcs::unload_item(), and heal_actor::use().

◆ is_firearm()

bool item::is_firearm ( ) const

Does it require gunsmithing tools to repair.

Definition at line 6522 of file item.cpp.

6523{
6524 static const std::string primitive_flag( "PRIMITIVE_RANGED_WEAPON" );
6525 return is_gun() && !has_flag( primitive_flag );
6526}

References has_flag(), and is_gun().

Referenced by repair_item_actor::can_repair_target(), iuse::gun_repair(), and repair_inventory_preset::is_shown().

◆ is_food()

◆ is_food_container()

bool item::is_food_container ( ) const

◆ is_fresh()

bool item::is_fresh ( ) const
inline

an item is fresh if it is capable of rotting but still has a long shelf life remaining

Definition at line 840 of file item.h.

840 {
841 return goes_bad() && get_relative_rot() < 0.1;
842 }

Referenced by comestible_inventory_preset::get_freshness(), get_freshness_description(), and tname().

◆ is_fuel()

bool item::is_fuel ( ) const

Definition at line 6760 of file item.cpp.

6761{
6762 return !!type->fuel;
6763}

References itype::fuel, and type.

Referenced by Character::can_fuel_bionic_with(), vehicle_part::consume_energy(), fuel_energy(), fuel_pump_terrain(), and has_explosion_data().

◆ is_funnel_container()

bool item::is_funnel_container ( units::volume bigger_than) const

Funnel related functions.

See weather.cpp for their usage.

Definition at line 6928 of file item.cpp.

6929{
6930 if( !is_bucket() && !is_watertight_container() ) {
6931 return false;
6932 }
6933 // TODO: consider linking funnel to item or -making- it an active item
6934 if( get_container_capacity() <= bigger_than ) {
6935 return false; // skip contents check, performance
6936 }
6937 if(
6938 contents.empty() ||
6942 bigger_than = get_container_capacity();
6943 return true;
6944 }
6945 return false;
6946}
bool is_watertight_container() const
Whether this is a container which can be used to store liquids.
Definition: item.cpp:6724
static const itype_id itype_water_acid_weak("water_acid_weak")
static const itype_id itype_water_acid("water_acid")
static const itype_id itype_water("water")

References contents, item_contents::empty(), item_contents::front(), get_container_capacity(), is_bucket(), is_watertight_container(), itype_water, itype_water_acid, itype_water_acid_weak, and typeId().

◆ is_going_bad()

bool item::is_going_bad ( ) const
inline

an item is about to become rotten when shelf life has nearly elapsed

Definition at line 845 of file item.h.

845 {
846 return get_relative_rot() > 0.9;
847 }

Referenced by get_freshness_description(), comestible_inventory_preset::get_time_left_rounded(), and tname().

◆ is_gun()

bool item::is_gun ( ) const

Can this item be used to perform a ranged attack?

See also
item::is_melee()
Note
an item can be both a gun and melee weapon concurrently

Definition at line 6517 of file item.cpp.

6518{
6519 return !!type->gun;
6520}

References itype::gun, and type.

Referenced by vehicle::add_item(), ranged::aim_per_move(), allow_crafting_component(), ammo_capacity(), ammo_consume(), character_funcs::ammo_count_for(), ammo_data(), ammo_effects(), ammo_info(), ammo_remaining(), ammo_required(), ammo_set(), ammo_sort_name(), ammo_types(), ammo_unset(), npc_ai::best_mode_for_range(), can_fire_turret(), avatar_action::can_fire_weapon(), saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), defense_game::caravan(), casings_handle(), npc::character_danger(), npc::check_or_use_weapon_cbm(), color_in_inventory(), npc::confident_shoot_range(), contents_info(), contextualize_skill(), damage_melee(), display_name(), durability_indicator(), final_info(), character_funcs::find_ammo_helper(), character_funcs::find_reloadables(), fire(), ranged::fire_gun(), avatar_action::fire_wielded_weapon(), character_funcs::fmt_wielded_weapon(), npc::form_opinion(), ranged::get_aim_types(), get_covered_body_parts(), get_encumber_when_containing(), get_free_mod_locations(), ranged::get_most_accurate_sight(), get_reload_time(), give_item_to(), gun_all_modes(), gun_cycle_mode(), gun_damage(), gun_dispersion(), gun_get_mode(), gun_get_mode_id(), gun_noise(), gun_range(), gun_recoil(), gun_set_mode(), gun_skill(), gun_type(), gunmod_info(), game::handle_action(), ranged::handle_gun_damage(), has_flag(), Character::i_add(), ideal_ranged_dps(), info(), character_effects::intimidation(), is_firearm(), is_gunmod_compatible(), is_reloadable(), gunmod_inventory_preset::is_shown(), saw_barrel_inventory_preset::is_shown(), saw_stock_inventory_preset::is_shown(), vehicle_part::is_turret(), Character::item_reload_cost(), Character::item_store_cost(), magazine_compatible(), magazine_default(), magazine_integral(), Item_modifier::modify(), item_reload_option::moves(), Character::on_dodge(), on_wield(), parse_tags(), tutorial_game::post_action(), Character::power_rating(), reach_range(), activity_handlers::reload_finish(), remove_ammo(), item_funcs::shots_remaining(), sight_dispersion(), starting_inv(), tname(), game::try_get_right_click_action(), character_funcs::try_wield_contents(), npc::value(), visit_internal(), volume(), weapon_inventory_preset::weapon_inventory_preset(), npc_ai::weapon_value(), weight(), and npc::wield_better_weapon().

◆ is_gunmod()

◆ is_gunmod_compatible()

ret_val< bool > item::is_gunmod_compatible ( const item mod) const

Definition at line 7764 of file item.cpp.

7765{
7766 if( !mod.is_gunmod() ) {
7767 debugmsg( "Tried checking compatibility of non-gunmod" );
7769 }
7770 static const gun_type_type pistol_gun_type( translate_marker_context( "gun_type_type", "pistol" ) );
7771 static const skill_id skill_archery( "archery" );
7772 static const std::string bow_hack_str( "bow" );
7773
7774 if( !is_gun() ) {
7775 return ret_val<bool>::make_failure( _( "isn't a weapon" ) );
7776
7777 } else if( is_gunmod() ) {
7778 return ret_val<bool>::make_failure( _( "is a gunmod and cannot be modded" ) );
7779
7780 } else if( gunmod_find( mod.typeId() ) ) {
7781 return ret_val<bool>::make_failure( _( "already has a %s" ), mod.tname( 1 ) );
7782
7783 } else if( !get_mod_locations().count( mod.type->gunmod->location ) ) {
7784 return ret_val<bool>::make_failure( _( "doesn't have a slot for this mod" ) );
7785
7786 } else if( get_free_mod_locations( mod.type->gunmod->location ) <= 0 ) {
7787 return ret_val<bool>::make_failure( _( "doesn't have enough room for another %s mod" ),
7788 mod.type->gunmod->location.name() );
7789
7790 // TODO: Get rid of the "archery"->"bow" hack
7791 } else if( !mod.type->gunmod->usable.count( gun_type() ) &&
7792 !mod.type->gunmod->usable.count( typeId().str() ) &&
7793 !( gun_skill() == skill_archery && mod.type->gunmod->usable.count( bow_hack_str ) > 0 ) ) {
7794 return ret_val<bool>::make_failure( _( "cannot have a %s" ), mod.tname() );
7795
7796 } else if( typeId() == itype_hand_crossbow &&
7797 !mod.type->gunmod->usable.count( pistol_gun_type ) ) {
7798 return ret_val<bool>::make_failure( _( "isn't big enough to use that mod" ) );
7799
7800 } else if( mod.type->gunmod->location.str() == "underbarrel" &&
7802 return ret_val<bool>::make_failure( _( "can only accept small mods on that slot" ) );
7803
7804 } else if( !mod.type->mod->acceptable_ammo.empty() ) {
7805 bool compat_ammo = false;
7806 for( const ammotype &at : mod.type->mod->acceptable_ammo ) {
7807 if( ammo_types( false ).count( at ) ) {
7808 compat_ammo = true;
7809 }
7810 }
7811 if( !compat_ammo ) {
7813 _( "%1$s cannot be used on item with no compatible ammo types" ), mod.tname( 1 ) );
7814 }
7815 } else if( mod.typeId() == itype_waterproof_gunmod && has_flag( flag_WATERPROOF_GUN ) ) {
7816 return ret_val<bool>::make_failure( _( "is already waterproof" ) );
7817
7818 } else if( mod.typeId() == itype_tuned_mechanism && has_flag( flag_NEVER_JAMS ) ) {
7819 return ret_val<bool>::make_failure( _( "is already eminently reliable" ) );
7820
7821 } else if( mod.typeId() == itype_brass_catcher && has_flag( flag_RELOAD_EJECT ) ) {
7822 return ret_val<bool>::make_failure( _( "cannot have a brass catcher" ) );
7823
7824 } else if( ( !mod.type->mod->ammo_modifier.empty() || !mod.type->mod->magazine_adaptor.empty() )
7825 && ( ammo_remaining() > 0 || magazine_current() ) ) {
7826 return ret_val<bool>::make_failure( _( "must be unloaded before installing this mod" ) );
7827 }
7828
7829 for( const gunmod_location &slot : mod.type->gunmod->blacklist_mod ) {
7830 if( get_mod_locations().count( slot ) ) {
7831 return ret_val<bool>::make_failure( _( "cannot be installed on a weapon with \"%s\"" ),
7832 slot.name() );
7833 }
7834 }
7835
7837}
std::string name() const
Returns the translated name.
Definition: itype.cpp:15
gun_type_type gun_type() const
Get the type of a ranged weapon (e.g.
Definition: item.cpp:7195
static ret_val make_success(T val=default_success::value)
Definition: ret_val.h:42
static ret_val make_failure(T val=default_failure::value)
Definition: ret_val.h:46
static const std::string flag_RELOAD_EJECT("RELOAD_EJECT")
static const itype_id itype_brass_catcher("brass_catcher")
static const itype_id itype_hand_crossbow("hand_crossbow")
static const itype_id itype_waterproof_gunmod("waterproof_gunmod")
static const itype_id itype_tuned_mechanism("tuned_mechanism")
static const std::string flag_PUMP_ACTION("PUMP_ACTION")
static const std::string flag_NEVER_JAMS("NEVER_JAMS")
static const std::string flag_WATERPROOF_GUN("WATERPROOF_GUN")
static const std::string flag_PUMP_RAIL_COMPATIBLE("PUMP_RAIL_COMPATIBLE")
static const skill_id skill_archery("archery")

References _, ammo_remaining(), ammo_types(), count(), debugmsg, flag_NEVER_JAMS(), flag_PUMP_ACTION(), flag_PUMP_RAIL_COMPATIBLE(), flag_RELOAD_EJECT(), flag_WATERPROOF_GUN(), get_free_mod_locations(), get_mod_locations(), gun_skill(), gun_type(), gunmod_find(), has_flag(), is_gun(), is_gunmod(), itype_brass_catcher, itype_hand_crossbow, itype_tuned_mechanism, itype_waterproof_gunmod, magazine_current(), ret_val< T >::make_failure(), ret_val< T >::make_success(), gunmod_location::name(), skill_archery, translate_marker_context, and typeId().

Referenced by gunmod_inventory_preset::get_denial(), avatar_funcs::gunmod_add(), and activity_handlers::gunmod_add_finish().

◆ is_holster()

bool item::is_holster ( ) const

Definition at line 6577 of file item.cpp.

6578{
6579 return type->can_use( "holster" );
6580}

References itype::can_use(), and type.

Referenced by character_funcs::find_reloadables(), get_total_capacity(), and npc::wield().

◆ is_irremovable()

bool item::is_irremovable ( ) const

Definition at line 6775 of file item.cpp.

6776{
6777 return has_flag( flag_IRREMOVABLE );
6778}
static const std::string flag_IRREMOVABLE("IRREMOVABLE")

References flag_IRREMOVABLE(), and has_flag().

Referenced by allow_crafting_component(), detach_gunmods_actor::can_use(), remove_ammo(), and detach_gunmods_actor::use().

◆ is_magazine()

◆ is_map()

bool item::is_map ( ) const

Definition at line 6714 of file item.cpp.

6715{
6716 return get_category().get_id() == itemcat_maps;
6717}
item_category_id get_id() const
static const item_category_id itemcat_maps("maps")

References get_category(), item_category::get_id(), and itemcat_maps.

Referenced by map::add_item(), and display_name().

◆ is_med_container()

bool item::is_med_container ( ) const

Definition at line 6615 of file item.cpp.

6616{
6617 return !contents.empty() && contents.front().is_medication();
6618}

References contents, item_contents::empty(), item_contents::front(), and is_medication().

Referenced by info().

◆ is_medication()

◆ is_melee() [1/2]

bool item::is_melee ( ) const

Is this item an effective melee weapon for any damage type?

See also
item::is_gun()
Note
an item can be both a gun and melee weapon concurrently

Definition at line 6667 of file item.cpp.

6668{
6669 for( int idx = DT_NULL + 1; idx != NUM_DT; ++idx ) {
6670 if( is_melee( static_cast<damage_type>( idx ) ) ) {
6671 return true;
6672 }
6673 }
6674 return false;
6675}

References DT_NULL, is_melee(), and NUM_DT.

Referenced by contextualize_skill(), is_melee(), melee_skill(), and on_wield().

◆ is_melee() [2/2]

bool item::is_melee ( damage_type  dt) const

Is this item an effective melee weapon for the given damage type?

Definition at line 6677 of file item.cpp.

6678{
6679 return damage_melee( dt ) > MELEE_STAT;
6680}
static constexpr int MELEE_STAT

References damage_melee(), and MELEE_STAT.

Referenced by iexamine::cvdmachine(), Character::i_add(), tutorial_game::post_action(), and npc::wield_better_weapon().

◆ is_money()

bool item::is_money ( ) const

Definition at line 6000 of file item.cpp.

6001{
6002 return ammo_types().count( ammotype( "money" ) );
6003}

References ammo_types().

Referenced by ammo_set(), display_name(), inventory_selector_preset::get_caption(), selection_column_preset::get_caption(), operator<(), and stacks_with().

◆ is_non_resealable_container()

bool item::is_non_resealable_container ( ) const

Whether removing this item's contents will permanently alter it.

Definition at line 6729 of file item.cpp.

6730{
6731 return type->container && !type->container->seals && type->container->unseals_into;
6732}

References itype::container, and type.

Referenced by deserialize(), advanced_inventory::move_content(), and on_contents_changed().

◆ is_null()

bool item::is_null ( ) const

Definition at line 732 of file item.cpp.

733{
734 // Actually, type should never by null at all.
735 return ( type == nullptr || type == nullitem() || typeId().is_null() );
736}

References is_null(), nullitem(), type, and typeId().

Referenced by acid_resist(), npc::address_needs(), ammo_set(), Character::apply_damage(), base_volume(), bash_resist(), Character::block_hit(), Character::block_ranged_hit(), bullet_resist(), Character::can_eat(), vehicle_part::can_reload(), repair_item_actor::can_repair_target(), Character::can_use(), debug_menu::character_edit_menu(), color(), colorized_feature_description_at(), veh_interact::complete_vehicle(), conductive(), Character::consume_item(), cut_resist(), damage_melee(), display_name(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), anonymous_namespace{iexamine.cpp}::atm_menu::do_withdraw_money(), drop_or_embed_projectile(), enumerate_objects_around_point(), Character::extended_description(), final_info(), find_auto_consume(), fire_resist(), inventory::form_from_map(), iexamine::gaspump(), liquid_handler::get_liquid_target(), SkillLevelMap::get_skill_level(), aim_activity_actor::get_weapon(), Character::handle_melee_wear(), npc::has_healing_item(), npc::heal_player(), npc::heal_self(), Character::i_add_or_drop(), info(), npc_trading::init_buying(), Character::is_armed(), is_null(), is_old_owner(), is_owned_by(), is_salvageable(), is_unarmed_weapon(), Character::item_encumb(), Character::item_reload_cost(), npc::load(), made_of(), Character::meets_requirements(), Character::melee_attack(), melee_train(), Item_modifier::modify(), explosion_handler::ExplosionProcess::move_entity(), item_location::impl::item_on_map::obtain(), item_location::impl::item_on_person::obtain(), item_location::impl::item_on_vehicle::obtain(), item_location::impl::item_in_container::obtain(), item_location::impl::item_on_map::obtain_cost(), item_location::impl::item_on_person::obtain_cost(), item_location::impl::item_on_vehicle::obtain_cost(), monexamine::pet_menu(), photo_def_for_camera_point(), rcdrive(), player::reduce_charges(), reinforceable(), bandolier_actor::reload(), reload(), Character::roll_bash_damage(), Character::roll_cut_damage(), Character::roll_stab_damage(), projectile::set_drop(), set_snippet(), npc::shop_restock(), map::spawn_items(), starting_inv(), Character::store(), npc::store(), holster_actor::store(), Character::suffer_from_schizophrenia(), Character::throw_range(), tname(), salvage_actor::try_to_cut_up(), Character::unarmed_attack(), Character::unwield(), avatar_funcs::use_item(), npc::use_painkiller(), salvage_actor::valid_to_cut_up(), volume(), martialart::weapon_valid(), Character::wear_possessed(), weight(), npc::wield(), avatar::wield(), npc::wield_better_weapon(), and Character::wielded_items().

◆ is_old_owner()

bool item::is_old_owner ( const Character c,
bool  available_to_take = false 
) const

Definition at line 1249 of file item.cpp.

1250{
1251 if( get_old_owner().is_null() ) {
1252 return available_to_take;
1253 }
1254 if( !c.get_faction() ) {
1255 debugmsg( "Character %s has no faction.", c.disp_name() );
1256 return false;
1257 }
1258 return c.get_faction()->id == get_old_owner();
1259}
faction_id get_old_owner() const
Definition: item.cpp:1285

References c, debugmsg, get_old_owner(), and is_null().

◆ is_owned_by()

bool item::is_owned_by ( const Character c,
bool  available_to_take = false 
) const

Definition at line 1234 of file item.cpp.

1235{
1236 // owner.is_null() implies faction_id( "no_faction" ) which shouldn't happen, or no owner at all.
1237 // either way, certain situations this means the thing is available to take.
1238 // in other scenarios we actually really want to check for id == id, even for no_faction
1239 if( get_owner().is_null() ) {
1240 return available_to_take;
1241 }
1242 if( !c.get_faction() ) {
1243 debugmsg( "Character %s has no faction", c.disp_name() );
1244 return false;
1245 }
1246 return c.get_faction()->id == get_owner();
1247}

References c, debugmsg, get_owner(), and is_null().

Referenced by activity_on_turn_move_loot(), move_items_activity_actor::do_turn(), find_auto_consume(), handle_pickup_ownership(), npc_trading::init_buying(), pick_one_up(), pickup::pick_up(), query_consume_ownership(), and npc::wants_to_sell().

◆ is_pet_armor()

bool item::is_pet_armor ( bool  on_pet = false) const

Definition at line 6698 of file item.cpp.

6699{
6700 bool is_worn = on_pet && !get_var( "pet_armor", "" ).empty();
6701 return has_flag( flag_IS_PET_ARMOR ) && ( is_worn || !on_pet );
6702}
static const std::string flag_IS_PET_ARMOR("IS_PET_ARMOR")

References flag_IS_PET_ARMOR(), get_var(), and has_flag().

Referenced by animal_armor_info(), armor_protection_info(), get_base_env_resist(), get_base_env_resist_w_filter(), get_env_resist(), get_pet_armor_bodytype(), get_pet_armor_max_vol(), get_pet_armor_min_vol(), get_storage(), and get_thickness().

◆ is_power_armor()

bool item::is_power_armor ( ) const

Whether this is a power armor item.

Not necessarily the main armor, it could be a helmet or similar.

Definition at line 5786 of file item.cpp.

5787{
5790}
static const std::string flag_POWERARMOR_MOD("POWERARMOR_MOD")

References flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_POWERARMOR_MOD(), and has_flag().

Referenced by armor_fit_info(), Character::can_wear(), Character::consume_charges(), final_info(), Character::has_enough_charges(), process_tool(), units_remaining(), and set_transform_iuse::use().

◆ is_relic()

bool item::is_relic ( ) const

Definition at line 6973 of file item.cpp.

6974{
6975 return !!relic_data;
6976}

References relic_data.

Referenced by get_enchantments(), mutations_from_wearing(), process_relic(), and stacks_with().

◆ is_reloadable()

bool item::is_reloadable ( ) const

Is it ever possible to reload this item? Only the base item is considered with any mods ignored.

See also
player::can_reload()

Definition at line 9830 of file item.cpp.

9831{
9833 return false; // turrets ignore NO_RELOAD flag
9834
9835 } else if( is_bandolier() ) {
9836 return true;
9837
9838 } else if( is_container() ) {
9839 return true;
9840
9841 } else if( !is_gun() && !is_tool() && !is_magazine() ) {
9842 return false;
9843
9844 } else if( ammo_types().empty() ) {
9845 return false;
9846 }
9847
9848 return true;
9849}
static const std::string flag_VEHICLE("VEHICLE")

References ammo_types(), flag_NO_RELOAD(), flag_VEHICLE(), has_flag(), is_bandolier(), is_container(), is_gun(), is_magazine(), and is_tool().

Referenced by can_reload_item_or_mods(), is_reloadable_helper(), and examine_item_menu::rate_action_reload().

◆ is_reloadable_helper()

bool item::is_reloadable_helper ( const itype_id ammo,
bool  now 
) const
private

Helper for checking reloadability.

Definition at line 6876 of file item.cpp.

6877{
6878 // empty ammo is passed for listing possible ammo apparently, so it needs to return true.
6879 if( !is_reloadable() ) {
6880 return false;
6881 } else if( is_watertight_container() ) {
6882 if( ammo.is_empty() ) {
6883 return now ? !is_container_full() : true;
6884 } else if( ammo->phase != LIQUID ) {
6885 return false;
6886 } else {
6887 return now ? ( is_container_empty() || contents.front().typeId() == ammo ) : true;
6888 }
6889 } else if( magazine_integral() ) {
6890 if( !ammo.is_empty() ) {
6891 if( now && ammo_data() ) {
6892 if( ammo_current() != ammo ) {
6893 return false;
6894 }
6895 } else {
6896 const itype *at = &*ammo;
6897 if( ( !at->ammo || !ammo_types().count( at->ammo->type ) ) &&
6898 !magazine_compatible().count( ammo ) ) {
6899 return false;
6900 }
6901 }
6902 }
6903 return now ? ( ammo_remaining() < ammo_capacity() ) : true;
6904 } else {
6905 return ammo.is_empty() ? true : magazine_compatible().count( ammo );
6906 }
6907}
bool is_reloadable() const
Is it ever possible to reload this item? Only the base item is considered with any mods ignored.
Definition: item.cpp:9830
bool is_container_full(bool allow_bucket=false) const
Whether this item has no more free capacity for its current content.
Definition: item.cpp:6842

References itype::ammo, ammo_capacity(), ammo_current(), ammo_data(), ammo_remaining(), ammo_types(), contents, count(), item_contents::front(), is_container_empty(), is_container_full(), string_id< T >::is_empty(), is_reloadable(), is_watertight_container(), LIQUID, magazine_compatible(), magazine_integral(), itype::phase, and typeId().

Referenced by can_reload_with(), and is_reloadable_with().

◆ is_reloadable_with()

bool item::is_reloadable_with ( const itype_id ammo) const

Returns true if this item can be reloaded with specified ammo type at this moment.

Definition at line 6871 of file item.cpp.

6872{
6873 return is_reloadable_helper( ammo, true );
6874}

References is_reloadable_helper().

Referenced by Character::can_reload(), vehicle_part::can_reload(), fill_with(), get_remaining_capacity_for_liquid(), and reload().

◆ is_salvageable()

bool item::is_salvageable ( ) const

Definition at line 6909 of file item.cpp.

6910{
6911 if( is_null() ) {
6912 return false;
6913 }
6914 const std::vector<material_id> &mats = made_of();
6915 if( std::none_of( mats.begin(), mats.end(), []( const material_id & m ) {
6916 return m->salvaged_into().has_value();
6917 } ) ) {
6918 return false;
6919 }
6920 return !has_flag( flag_NO_SALVAGE );
6921}
static const std::string flag_NO_SALVAGE("NO_SALVAGE")

References flag_NO_SALVAGE(), has_flag(), is_null(), and made_of().

Referenced by salvage_actor::try_to_cut_up(), and salvage_actor::valid_to_cut_up().

◆ is_seed()

bool item::is_seed ( ) const

Whether this is actually a seed, the seed functions won't be of much use for non-seeds.

Definition at line 9774 of file item.cpp.

9775{
9776 return !!type->seed;
9777}

References itype::seed, and type.

Referenced by can_do_activity_there(), iexamine::dirtmound(), farm_valid_seed(), talk_function::field_plant(), plot_options::get_zone_name_suggestion(), plot_options::query_seed(), vehicle::reload_seeds(), and map::rotten_item_spawn().

◆ is_sided()

bool item::is_sided ( ) const

Returns true if item is armor and can be worn on different sides of the body.

Definition at line 802 of file item.cpp.

803{
804 const islot_armor *t = find_armor_data();
805 return t ? t->sided : false;
806}

References find_armor_data(), and islot_armor::sided.

Referenced by armor_fit_info(), armor_info(), Character::can_wear(), on_takeoff(), on_wear(), examine_item_menu::rate_action_change_side(), and set_side().

◆ is_silent()

bool item::is_silent ( ) const

Whether this is a (nearly) silent gun (a tiny bit of sound is allowed).

Non-guns are always silent.

Definition at line 6542 of file item.cpp.

6543{
6544 return gun_noise().volume < 5;
6545}
sound_data gun_noise(bool burst=false) const
Returns the sound of the gun being fired.
Definition: ranged.cpp:1815
int volume
Volume of the sound.
Definition: item.h:1851

References gun_noise(), and item::sound_data::volume.

Referenced by npc::check_or_use_weapon_cbm(), and npc::method_of_attack().

◆ is_soft()

bool item::is_soft ( ) const

Is this item flexible enough to be worn on body parts like antlers?

Definition at line 9822 of file item.cpp.

9823{
9824 const std::vector<material_id> mats = made_of();
9825 return std::any_of( mats.begin(), mats.end(), []( const material_id & mid ) {
9826 return mid.obj().soft();
9827 } );
9828}

References made_of().

Referenced by mutation_branch::conflicts_with_item(), and game_menus::inv::multiwash().

◆ is_tainted()

bool item::is_tainted ( ) const

Is item derived from a zombie?

Definition at line 9817 of file item.cpp.

9818{
9819 return corpse && corpse->has_flag( MF_POISON );
9820}
@ MF_POISON
Definition: mtype.h:80

References corpse, mtype::has_flag(), and MF_POISON.

Referenced by food_info().

◆ is_tool()

◆ is_toolmod()

bool item::is_toolmod ( ) const

Definition at line 6765 of file item.cpp.

6766{
6767 return !is_gunmod() && type->mod;
6768}

References is_gunmod(), itype::mod, and type.

Referenced by allow_crafting_component(), item_action_generator::map_actions_to_items(), iuse::multicooker(), and iuse::toolmod_attach().

◆ is_transformable()

bool item::is_transformable ( ) const

Definition at line 6963 of file item.cpp.

6964{
6965 return type->use_methods.find( "transform" ) != type->use_methods.end();
6966}

References type, and itype::use_methods.

Referenced by map::add_item().

◆ is_two_handed()

bool item::is_two_handed ( const Character guy) const

Whether the character needs both hands to wield this item.

Strength determines which weapons can be wielded with one hand

Definition at line 6404 of file item.cpp.

6405{
6406 if( has_flag( flag_ALWAYS_TWOHAND ) ) {
6407 return true;
6408 }
6409 ///\EFFECT_STR determines which weapons can be wielded with one hand
6410 return ( ( weight() / 113_gram ) > guy.str_cur * 4 );
6411}
int str_cur
Definition: character.h:264
static const std::string flag_ALWAYS_TWOHAND("ALWAYS_TWOHAND")

References flag_ALWAYS_TWOHAND(), has_flag(), Character::str_cur, and weight().

Referenced by Character::can_wear(), Character::can_wield(), ranged::gunmode_checks_common(), hardcoded_mutation_attack(), Character::item_handling_cost(), and Character::melee_special_effects().

◆ is_unarmed_weapon()

bool item::is_unarmed_weapon ( ) const

Definition at line 738 of file item.cpp.

739{
740 return has_flag( flag_UNARMED_WEAPON ) || is_null();
741}
static const std::string flag_UNARMED_WEAPON("UNARMED_WEAPON")

References flag_UNARMED_WEAPON(), has_flag(), and is_null().

Referenced by Character::crit_chance(), melee_train(), Character::roll_bash_damage(), Character::roll_cut_damage(), and Character::roll_stab_damage().

◆ is_upgrade()

bool item::is_upgrade ( ) const

Whether the CBM is an upgrade to another bionic module.

Definition at line 10036 of file item.cpp.

10037{
10038 if( !type->bionic ) {
10039 return false;
10040 }
10041 return type->bionic->is_upgrade;
10042}

References itype::bionic, and type.

Referenced by bionic_install_preset::get_denial(), and bionic_install_surgeon_preset::get_denial().

◆ is_watertight_container()

bool item::is_watertight_container ( ) const

◆ is_wheel()

bool item::is_wheel ( ) const

Definition at line 6755 of file item.cpp.

6756{
6757 return !!type->wheel;
6758}
cata::value_ptr< islot_wheel > wheel
Definition: itype.h:857

References type, and itype::wheel.

Referenced by can_do_activity_there(), tname(), wheel_area(), vehicle_part::wheel_diameter(), and vehicle_part::wheel_width().

◆ is_worn_only_with()

bool item::is_worn_only_with ( const item it) const

Returns true whether this item can be worn only when.

Parameters
itis worn.

Definition at line 835 of file item.cpp.

836{
839}

References flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_POWERARMOR_MOD(), and has_flag().

Referenced by Character::get_dependent_worn_items(), and pickup::reorder_for_dropping().

◆ item_has_uses_recursive()

bool item::item_has_uses_recursive ( ) const

Definition at line 80 of file item_action.cpp.

81{
82 if( !type->use_methods.empty() ) {
83 return true;
84 }
85
87}
bool item_has_uses_recursive() const
Definition: item_action.cpp:89

References contents, item_contents::item_has_uses_recursive(), type, and itype::use_methods.

◆ label()

std::string item::label ( unsigned int  quantity = 0) const

Returns label from "item_label" itemvar and quantity.

Definition at line 9952 of file item.cpp.

9953{
9954 if( has_label() ) {
9955 return get_var( "item_label" );
9956 }
9957
9958 return type_name( quantity );
9959}
std::string type_name(unsigned int quantity=1) const
Name of the item type (not the item), with proper plural.
Definition: item.cpp:9851
bool has_label() const
Returns true if item has "item_label" itemvar.
Definition: item.cpp:9947

References get_var(), has_label(), and type_name().

Referenced by tname().

◆ legacy_fast_forward_time()

void item::legacy_fast_forward_time ( )

Definition at line 10015 of file item.cpp.

10016{
10017 const time_duration tmp_bday = ( bday - calendar::turn_zero ) * 6;
10018 bday = calendar::turn_zero + tmp_bday;
10019
10020 rot *= 6;
10021
10022 const time_duration tmp_rot = ( last_rot_check - calendar::turn_zero ) * 6;
10024}

References bday, last_rot_check, and calendar::turn_zero.

Referenced by deserialize(), and submap::load().

◆ lift_strength()

int item::lift_strength ( ) const

Required strength to be able to successfully lift the item unaided by equipment.

Definition at line 5175 of file item.cpp.

5176{
5177 const int mass = units::to_gram( weight() );
5178 return std::max( mass / 10000, 1 );
5179}
constexpr value_type to_gram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:68
quantity< std::int64_t, mass_in_milligram_tag > mass
Definition: units_mass.h:23

References units::to_gram(), and weight().

Referenced by can_do_activity_there(), veh_interact::can_remove_part(), and veh_interact::update_part_requirements().

◆ made_of() [1/3]

const std::vector< material_id > & item::made_of ( ) const

The ids of all the materials this is made of.

This may return an empty vector. The returned vector does not contain the null id.

Definition at line 6413 of file item.cpp.

6414{
6415 if( is_corpse() ) {
6416 return corpse->mat;
6417 }
6418 return type->materials;
6419}
std::vector< material_id > materials
Definition: itype.h:922
std::vector< material_id > mat
Definition: mtype.h:254

References corpse, is_corpse(), mtype::mat, itype::materials, and type.

Referenced by activity_on_turn_move_loot(), map::add_item(), map::add_item_or_charges(), avatar_funcs::add_or_drop_with_msg(), iuse::blech(), iuse::blech_because_unclean(), vehicle_part::can_reload(), can_unload_liquid(), saw_stock_actor::can_use_on(), Character::can_wear(), Character::can_wield(), MonsterGenerator::check_monster_definitions(), color_in_inventory(), crafting::complete_disassemble(), compute_default_effective_vitamins(), contents_made_of(), map::create_burnproducts(), auto_pickup::rule_list::create_rule(), salvage_actor::cut_up(), iexamine::cvdmachine(), move_items_activity_actor::do_turn(), Character::drop_invalid_inventory(), drop_or_handle(), final_info(), character_funcs::find_ammo_helper(), iexamine::fvat_empty(), iexamine::fvat_full(), Character::get_acquirable_energy(), get_base_material(), pickup_inventory_preset::get_denial(), comestible_inventory_preset::get_denial(), liquid_handler::get_liquid_target(), get_random_material(), repair_item_actor::handle_components(), liquid_handler::handle_liquid(), Character::i_add_or_drop(), in_container(), is_salvageable(), is_soft(), inscribe_actor::item_inscription(), iexamine::keg(), made_of(), made_of_any(), made_of_types(), Character::melee_special_effects(), Item_modifier::modify(), advanced_inventory::move_all_items(), advanced_inventory::move_content(), move_item(), iuse::multicooker(), npc_pickup_from_stack(), on_drop(), only_made_of(), liquid_handler::perform_liquid_transfer(), pick_one_up(), price(), monster::process_turn(), mattack::pull_metal_weapon(), item_reload_option::qty(), advanced_inventory::query_charges(), reload(), simulate_burn(), smash(), map::spawn_an_item(), starting_inv(), ranged::throw_item(), tname(), try_fuel_fire(), avatar_funcs::unload_item(), npc::value(), volume(), and Character::warmth().

◆ made_of() [2/3]

bool item::made_of ( const material_id mat_ident) const

Check we are made of this material (e.g.

matches at least one in our set.)

Definition at line 6459 of file item.cpp.

6460{
6461 const std::vector<material_id> &materials = made_of();
6462 return std::find( materials.begin(), materials.end(), mat_ident ) != materials.end();
6463}

References detail::find(), and made_of().

◆ made_of() [3/3]

bool item::made_of ( phase_id  phase) const

Are we solid, liquid, gas, plasma?

Definition at line 6470 of file item.cpp.

6471{
6472 if( is_null() ) {
6473 return false;
6474 }
6475 return type->phase == phase;
6476}

References is_null(), itype::phase, and type.

◆ made_of_any()

bool item::made_of_any ( const std::set< material_id > &  mat_idents) const

Check we are made of at least one of a set (e.g.

true if at least one item of the passed in set matches any material).

Parameters
mat_identsSet of material ids.

Definition at line 6435 of file item.cpp.

6436{
6437 const std::vector<material_id> &mats = made_of();
6438 if( mats.empty() ) {
6439 return false;
6440 }
6441
6442 return std::any_of( mats.begin(), mats.end(), [&mat_idents]( const material_id & e ) {
6443 return mat_idents.count( e );
6444 } );
6445}

References made_of().

Referenced by Character::can_eat(), goes_bad(), repair_inventory_preset::is_shown(), inscribe_actor::item_inscription(), ranged::throw_item(), and Character::throw_range().

◆ made_of_types()

std::vector< const material_type * > item::made_of_types ( ) const

Same as made_of(), but returns the material_type directly.

Definition at line 6426 of file item.cpp.

6427{
6428 std::vector<const material_type *> material_types_composed_of;
6429 for( const material_id &mat_id : made_of() ) {
6430 material_types_composed_of.push_back( &mat_id.obj() );
6431 }
6432 return material_types_composed_of;
6433}

References made_of().

Referenced by acid_resist(), bash_resist(), basic_info(), bullet_resist(), chip_resistance(), conductive(), cut_resist(), fire_resist(), flammable(), reinforceable(), and wind_resist().

◆ magazine_compatible()

std::set< itype_id > item::magazine_compatible ( bool  conversion = true) const

Get compatible magazines (if any) for this item.

Parameters
conversionwhether to include the effect of any flags or mods which convert item's ammo type
Returns
magazine compatibility which is always empty if item has integral magazine
See also
item::magazine_integral

Definition at line 7701 of file item.cpp.

7702{
7703 std::set<itype_id> mags = {};
7704 // mods that define magazine_adaptor may override the items usual magazines
7705 const std::vector<const item *> &mods = is_gun() ? gunmods() : toolmods();
7706 for( const item *m : mods ) {
7707 if( !m->type->mod->magazine_adaptor.empty() ) {
7708 for( const ammotype &atype : ammo_types( conversion ) ) {
7709 if( m->type->mod->magazine_adaptor.count( atype ) ) {
7710 std::set<itype_id> magazines_for_atype = m->type->mod->magazine_adaptor.find( atype )->second;
7711 mags.insert( magazines_for_atype.begin(), magazines_for_atype.end() );
7712 }
7713 }
7714 return mags;
7715 }
7716 }
7717
7718 for( const ammotype &atype : ammo_types( conversion ) ) {
7719 if( type->magazines.count( atype ) ) {
7720 std::set<itype_id> magazines_for_atype = type->magazines.find( atype )->second;
7721 mags.insert( magazines_for_atype.begin(), magazines_for_atype.end() );
7722 }
7723 }
7724 return mags;
7725}

References ammo_types(), gunmods(), is_gun(), itype::magazines, toolmods(), and type.

Referenced by mdeath::broken(), color_in_inventory(), character_funcs::find_reloadables(), gun_info(), avatar_funcs::gunmod_add(), is_reloadable_helper(), and tool_info().

◆ magazine_current() [1/2]

item * item::magazine_current ( )

Currently loaded magazine (if any)

Returns
current magazine or nullptr if either no magazine loaded or item has integral magazine
See also
item::magazine_integral

Definition at line 7727 of file item.cpp.

7728{
7729 return contents.get_item_with(
7730 []( const item & it ) {
7731 return it.is_magazine();
7732 } );
7733}
item * get_item_with(const std::function< bool(const item &)> &filter)

References contents, item_contents::get_item_with(), and is_magazine().

Referenced by ammo_capacity(), ammo_consume(), ammo_data(), ammo_remaining(), ammo_set(), ammo_unset(), item_funcs::can_be_unloaded(), turret_data::can_unload(), common_ammo_default(), cycle_action(), iuse::foodperson(), iuse::hand_crank(), is_gunmod_compatible(), character_funcs::list_ammo(), magazine_current(), Item_modifier::modify(), reload(), character_funcs::select_ammo(), tool_info(), iuse::toolmod_attach(), avatar_funcs::unload_item(), volume(), and weight().

◆ magazine_current() [2/2]

const item * item::magazine_current ( ) const

Definition at line 7735 of file item.cpp.

7736{
7737 return const_cast<item *>( this )->magazine_current();
7738}

References magazine_current().

◆ magazine_default()

itype_id item::magazine_default ( bool  conversion = true) const

Get the default magazine type (if any) for the current effective ammo type.

Parameters
conversionwhether to include the effect of any flags or mods which convert item's ammo type
Returns
magazine type or "null" if item has integral magazine or no magazines for current ammo type

Definition at line 7680 of file item.cpp.

7681{
7682 if( !ammo_types( conversion ).empty() ) {
7683 if( conversion ) {
7684 for( const item *m : is_gun() ? gunmods() : toolmods() ) {
7685 if( !m->type->mod->magazine_adaptor.empty() ) {
7686 auto mags = m->type->mod->magazine_adaptor.find( ammotype( *ammo_types( conversion ).begin() ) );
7687 if( mags != m->type->mod->magazine_adaptor.end() ) {
7688 return *( mags->second.begin() );
7689 }
7690 }
7691 }
7692 }
7693 auto mag = type->magazine_default.find( ammotype( *ammo_types( conversion ).begin() ) );
7694 if( mag != type->magazine_default.end() ) {
7695 return mag->second;
7696 }
7697 }
7698 return itype_id::NULL_ID();
7699}
std::map< ammotype, itype_id > magazine_default
Default magazine for each ammo type that can be used to reload this item.
Definition: itype.h:1023

References ammo_types(), gunmods(), is_gun(), itype::magazine_default, itype::mod, string_id< itype >::NULL_ID(), toolmods(), and type.

Referenced by ammo_capacity(), ammo_set(), defense_game::caravan(), game::dump_stats(), and Item_modifier::modify().

◆ magazine_info()

void item::magazine_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1881 of file item.cpp.

1883{
1884 if( !is_magazine() || has_flag( flag_NO_RELOAD ) ) {
1885 return;
1886 }
1887
1888 if( parts->test( iteminfo_parts::MAGAZINE_CAPACITY ) ) {
1889 for( const ammotype &at : ammo_types() ) {
1890 const std::string fmt = string_format( vgettext( "<num> round of %s",
1891 "<num> rounds of %s", ammo_capacity() ),
1892 at->name() );
1893 info.emplace_back( "MAGAZINE", _( "Capacity: " ), fmt, iteminfo::no_flags,
1894 ammo_capacity() );
1895 }
1896 }
1897 if( parts->test( iteminfo_parts::MAGAZINE_RELOAD ) ) {
1898 info.emplace_back( "MAGAZINE", _( "Reload time: " ), _( "<num> moves per round" ),
1899 iteminfo::lower_is_better, type->magazine->reload_time );
1900 }
1902}

References _, ammo_capacity(), ammo_types(), flag_NO_RELOAD(), has_flag(), info(), insert_separation_line(), is_magazine(), iteminfo::lower_is_better, itype::magazine, MAGAZINE_CAPACITY, MAGAZINE_RELOAD, iteminfo::no_flags, string_format(), iteminfo_query::test(), type, and vgettext().

Referenced by info().

◆ magazine_integral()

bool item::magazine_integral ( ) const

Does item have an integral magazine (as opposed to allowing detachable magazines)

Definition at line 7665 of file item.cpp.

7666{
7667 if( is_gun() && type->gun->clip > 0 ) {
7668 return true;
7669 }
7670 for( const item *m : is_gun() ? gunmods() : toolmods() ) {
7671 if( !m->type->mod->magazine_adaptor.empty() ) {
7672 return false;
7673 }
7674 }
7675
7676 // We have an integral magazine if we're a gun with an ammo capacity (clip) or we have no magazines.
7677 return ( is_gun() && type->gun->clip > 0 ) || type->magazines.empty();
7678}

References itype::gun, gunmods(), is_gun(), itype::magazines, toolmods(), and type.

Referenced by character_funcs::ammo_count_for(), ammo_set(), ammo_unset(), turret_data::can_reload(), defense_game::caravan(), color_in_inventory(), game::dump_stats(), character_funcs::fmt_wielded_weapon(), gun_info(), avatar_funcs::gunmod_add(), ideal_ranged_dps(), is_reloadable_helper(), item(), Item_modifier::modify(), price(), reload(), character_funcs::select_ammo(), tool_info(), wants_to_reload_with(), and weight().

◆ make_component_hash()

uint64_t item::make_component_hash ( ) const

Creates a hash from the itype_ids of this item's components.

Definition at line 8918 of file item.cpp.

8919{
8920 // First we need to sort the IDs so that identical ingredients give identical hashes.
8921 std::multiset<std::string> id_set;
8922 for( const item &it : components ) {
8923 id_set.insert( it.typeId().str() );
8924 }
8925
8926 std::string concatenated_ids;
8927 for( std::string id : id_set ) {
8928 concatenated_ids += id;
8929 }
8930
8931 std::hash<std::string> hasher;
8932 return hasher( concatenated_ids );
8933}

References components, base_camps::id, and string_id< T >::str().

Referenced by consumption_event::consumption_event(), and Character::fun_for().

◆ make_corpse()

item item::make_corpse ( const mtype_id mt = string_id<mtype>::NULL_ID(),
time_point  turn = calendar::turn,
const std::string &  name = "",
int  upgrade_time = -1 
)
static

Make a corpse of the given monster type.

The monster type id must be valid (see MonsterGenerator::get_all_mtypes).

The turn parameter sets the birthday of the corpse, in other words: the turn when the monster died. Because corpses are removed from the map when they reach a certain age, one has to be careful when placing corpses with a birthday of 0. They might be removed immediately when the map is loaded without been seen by the player.

The name parameter can be used to give the corpse item a name. This is used instead of the monster type name ("corpse of X" instead of "corpse of bear").

With the default parameters it makes a human corpse, created at the current turn.

Definition at line 507 of file item.cpp.

509{
510 if( !mt.is_valid() ) {
511 debugmsg( "tried to make a corpse with an invalid mtype id" );
512 }
513
514 std::string corpse_type = mt == mtype_id::NULL_ID() ? "corpse_generic_human" : "corpse";
515
516 item result( corpse_type, turn );
517 result.corpse = &mt.obj();
518
519 if( result.corpse->has_flag( MF_REVIVES ) ) {
520 if( one_in( 20 ) ) {
521 result.set_flag( "REVIVE_SPECIAL" );
522 }
523 result.set_var( "upgrade_time", std::to_string( upgrade_time ) );
524 }
525
526 // This is unconditional because the const itemructor above sets result.name to
527 // "human corpse".
528 result.corpse_name = name;
529
530 return result;
531}
std::string to_string(const time_duration &d)
Returns a string showing a duration.
Definition: calendar.cpp:327
bool one_in(int chance)
Definition: rng.cpp:65

References debugmsg, string_id< T >::is_valid(), MF_REVIVES, om_direction::name(), string_id< mtype >::NULL_ID(), string_id< T >::obj(), one_in(), to_string(), and calendar::turn.

Referenced by map::add_corpse(), game::catch_a_monster(), Single_item_creator::create_single(), map::draw_mine(), iuse::fish_trap(), basecamp::hunting_results(), make_mon_corpse(), MapExtras::mx_grave(), MapExtras::mx_mayhem(), MapExtras::mx_minefield(), Character::place_corpse(), rod_fish(), and mdeath::splatter().

◆ mark_as_used_by_player()

void item::mark_as_used_by_player ( const player p)

Marks the item as being used by this specific player, it remains unmarked for other players.

The player is identified by its id.

Definition at line 8866 of file item.cpp.

8867{
8868 std::string &used_by_ids = item_vars[ USED_BY_IDS ];
8869 if( used_by_ids.empty() ) {
8870 // *always* start with a ';'
8871 used_by_ids = ";";
8872 }
8873 // and always end with a ';'
8874 used_by_ids += string_format( "%d;", p.getID().get_value() );
8875}

References character_id::get_value(), Character::getID(), item_vars, string_format(), and USED_BY_IDS().

Referenced by reveal_map_actor::use().

◆ mark_chapter_as_read()

void item::mark_chapter_as_read ( const Character ch)

Mark one chapter of the book as read by the given player.

May do nothing if the book has no unread chapters. This is a per-character setting, see get_remaining_chapters.

Definition at line 7103 of file item.cpp.

7104{
7105 const std::string var = string_format( "remaining-chapters-%d", ch.getID().get_value() );
7106 if( type->book && type->book->chapters == 0 ) {
7107 // books without chapters will always have remaining chapters == 0, so we don't need to store them
7108 erase_var( var );
7109 return;
7110 }
7111 const int remain = std::max( 0, get_remaining_chapters( ch ) - 1 );
7112 set_var( var, remain );
7113}
void erase_var(const std::string &name)
Erase the value of the given variable.
Definition: item.cpp:1080

References itype::book, erase_var(), get_remaining_chapters(), character_id::get_value(), Character::getID(), set_var(), string_format(), and type.

Referenced by avatar::do_read(), and npc::finish_read().

◆ max_damage()

◆ med_info()

void item::med_info ( const item med_item,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1641 of file item.cpp.

1643{
1644 const cata::value_ptr<islot_comestible> &med_com = med_item->get_comestible();
1645 if( med_com->quench != 0 && parts->test( iteminfo_parts::MED_QUENCH ) ) {
1646 info.push_back( iteminfo( "MED", _( "Quench: " ), med_com->quench ) );
1647 }
1648
1649 if( med_item->get_comestible_fun() != 0 && parts->test( iteminfo_parts::MED_JOY ) ) {
1650 info.push_back( iteminfo( "MED", _( "Enjoyability: " ),
1651 get_avatar().fun_for( *med_item ).first ) );
1652 }
1653
1654 if( med_com->stim != 0 && parts->test( iteminfo_parts::MED_STIMULATION ) ) {
1655 std::string name = string_format( "%s <stat>%s</stat>", _( "Stimulation:" ),
1656 med_com->stim > 0 ? _( "Upper" ) : _( "Downer" ) );
1657 info.push_back( iteminfo( "MED", name ) );
1658 }
1659
1660 if( parts->test( iteminfo_parts::MED_PORTIONS ) ) {
1661 info.push_back( iteminfo( "MED", _( "Portions: " ),
1662 std::abs( static_cast<int>( med_item->charges ) * batch ) ) );
1663 }
1664
1665 if( med_com->addict && parts->test( iteminfo_parts::DESCRIPTION_MED_ADDICTING ) ) {
1666 info.emplace_back( "DESCRIPTION", _( "* Consuming this item is <bad>addicting</bad>." ) );
1667 }
1668}
int get_comestible_fun() const
Definition: item.cpp:5482

References _, charges, DESCRIPTION_MED_ADDICTING, get_avatar(), get_comestible(), get_comestible_fun(), info(), MED_JOY, MED_PORTIONS, MED_QUENCH, MED_STIMULATION, om_direction::name(), string_format(), and iteminfo_query::test().

Referenced by info().

◆ melee_skill()

skill_id item::melee_skill ( ) const

The most relevant skill used with this melee weapon.

Can be "null" if this is not a weapon. Note this function returns null if the item is a gun for which you can use gun_skill() instead.

Definition at line 7208 of file item.cpp.

7209{
7210 if( !is_melee() ) {
7211 return skill_id::NULL_ID();
7212 }
7213
7214 if( has_flag( flag_UNARMED_WEAPON ) ) {
7215 return skill_unarmed;
7216 }
7217
7218 int hi = 0;
7220
7221 for( int idx = DT_NULL + 1; idx != NUM_DT; ++idx ) {
7222 const int val = damage_melee( static_cast<damage_type>( idx ) );
7223 const skill_id &sk = skill_by_dt( static_cast<damage_type>( idx ) );
7224 if( val > hi && sk ) {
7225 hi = val;
7226 res = sk;
7227 }
7228 }
7229
7230 return res;
7231}
const skill_id & skill_by_dt(damage_type dt)
Definition: damage.cpp:273
static const skill_id skill_unarmed("unarmed")

References damage_melee(), DT_NULL, flag_UNARMED_WEAPON(), has_flag(), is_melee(), string_id< Skill >::NULL_ID(), NUM_DT, skill_by_dt(), and skill_unarmed.

Referenced by contextualize_skill(), Character::crit_chance(), Character::get_hit_weapon(), Character::item_store_cost(), on_wield(), and character_funcs::try_wield_contents().

◆ merge_charges()

bool item::merge_charges ( const item rhs)

Merge charges of the other item into this item.

Returns
true if the items have been merged, otherwise false. Merging is only done for items counted by charges (count_by_charges) and items that stack together (stacks_with).

Definition at line 976 of file item.cpp.

977{
978 if( !count_by_charges() || !stacks_with( rhs ) ) {
979 return false;
980 }
981 // Prevent overflow when either item has "near infinite" charges.
982 if( charges >= INFINITE_CHARGES / 2 || rhs.charges >= INFINITE_CHARGES / 2 ) {
984 return true;
985 }
986 // We'll just hope that the item counter represents the same thing for both items
987 if( item_counter > 0 || rhs.item_counter > 0 ) {
988 item_counter = ( static_cast<double>( item_counter ) * charges + static_cast<double>
989 ( rhs.item_counter ) * rhs.charges ) / ( charges + rhs.charges );
990 }
991 charges += rhs.charges;
992 return true;
993}

References charges, count_by_charges(), INFINITE_CHARGES, item_counter, and stacks_with().

Referenced by vehicle::add_item().

◆ min_damage()

int item::min_damage ( ) const

Minimum amount of damage to an item (state of maximum repair)

Definition at line 6211 of file item.cpp.

6212{
6213 return type->damage_min();
6214}
int damage_min() const
Definition: itype.cpp:46

References itype::damage_min(), and type.

Referenced by repair_item_actor::can_repair_target(), damage_color(), repair_item_actor::default_action(), iuse::gun_repair(), io(), mod_damage(), and set_damage().

◆ minimum_freshness_duration()

time_duration item::minimum_freshness_duration ( temperature_flag  temperature) const

Time that this item is guaranteed to stay fresh.

Parameters
temperatureTemperature flag used to cap the duration.
Returns
Remaining guaranteed freshness duration, assuming current storage conditions.

Definition at line 5700 of file item.cpp.

5701{
5703 unsigned long long rot_per_hour = get_hourly_rotpoints_at_temp( temperature_f );
5704
5705 if( rot_per_hour <= 0 || !type->comestible ) {
5707 }
5708
5709 time_duration remaining_rot = type->comestible->spoils - rot;
5710 // Has to be in int64 or it will overflow for long lasting food
5711 unsigned long long duration = to_turns<unsigned long long>( remaining_rot )
5712 * to_turns<unsigned long long>( 1_hours )
5713 / rot_per_hour;
5714 if( duration > to_turns<unsigned long long>( calendar::INDEFINITELY_LONG_DURATION ) ) {
5716 }
5717
5718 return time_duration::from_turns( static_cast<int>( duration ) );
5719}
static int temperature_flag_to_highest_temperature(temperature_flag temperature)
Definition: item.cpp:5682
const time_duration INDEFINITELY_LONG_DURATION
The expected duration of the cataclysm.

References itype::comestible, time_duration::from_turns(), get_hourly_rotpoints_at_temp(), calendar::INDEFINITELY_LONG_DURATION, rot, temperature_flag_to_highest_temperature(), and type.

Referenced by food_info().

◆ mitigate_damage()

void item::mitigate_damage ( damage_unit du) const

Assuming that specified du hit the armor, reduce du based on the item's resistance to the damage type.

This will never reduce du.amount below 0.

Definition at line 6363 of file item.cpp.

6364{
6365 const resistances res = resistances( *this );
6366 const float mitigation = res.get_effective_resist( du );
6367 du.amount -= mitigation;
6368 du.amount = std::max( 0.0f, du.amount );
6369}
float get_effective_resist(const damage_unit &du) const
Definition: damage.cpp:217

References damage_unit::amount, and resistances::get_effective_resist().

Referenced by Character::armor_absorb(), and character_funcs::is_bp_immune_to().

◆ mod_charges()

void item::mod_charges ( int  mod)

Modify the charges of this item, only use for items counted by charges! The item must have enough charges for this (>= quantity) and be counted by charges.

Parameters
modHow many charges should be removed.

Definition at line 9721 of file item.cpp.

9722{
9723 if( has_infinite_charges() ) {
9724 return;
9725 }
9726
9727 if( !count_by_charges() ) {
9728 debugmsg( "Tried to remove %s by charges, but item is not counted by charges.", tname() );
9729 } else if( mod < 0 && charges + mod < 0 ) {
9730 debugmsg( "Tried to remove charges that do not exist, removing maximum available charges instead." );
9731 charges = 0;
9732 } else if( mod > 0 && charges >= INFINITE_CHARGES - mod ) {
9733 charges = INFINITE_CHARGES - 1; // Highly unlikely, but finite charges should not become infinite.
9734 } else {
9735 charges += mod;
9736 }
9737}

References charges, count_by_charges(), debugmsg, has_infinite_charges(), INFINITE_CHARGES, and tname().

Referenced by throw_activity_actor::do_turn(), Character::eat(), fill_with(), player::reduce_charges(), and talk_effect_fun_t::set_u_buy_item().

◆ mod_damage() [1/2]

bool item::mod_damage ( int  qty)

same as other mod_damage, but uses DT_NULL as damage type.

Definition at line 6248 of file item.cpp.

6249{
6250 return mod_damage( qty, DT_NULL );
6251}

References DT_NULL, and mod_damage().

◆ mod_damage() [2/2]

bool item::mod_damage ( int  qty,
damage_type  dt 
)

Apply damage to const itemrained by min_damage and max_damage.

Parameters
qtymaximum amount by which to adjust damage (negative permissible)
dttype of damage which may be passed to on_damage callback
Returns
whether item should be destroyed

Definition at line 6226 of file item.cpp.

6227{
6228 bool destroy = false;
6229
6230 if( count_by_charges() ) {
6231 charges -= std::min( type->stack_size * qty / itype::damage_scale, charges );
6232 destroy |= charges == 0;
6233 }
6234
6235 if( qty > 0 ) {
6236 on_damage( qty, dt );
6237 }
6238
6239 if( !count_by_charges() ) {
6240 destroy |= damage_ + qty > max_damage();
6241
6242 damage_ = std::max( std::min( damage_ + qty, max_damage() ), min_damage() );
6243 }
6244
6245 return destroy;
6246}
void on_damage(int qty, damage_type dt)
Callback immediately before an item is damaged.
Definition: item.cpp:4547

References charges, count_by_charges(), damage_, itype::damage_scale, max_damage(), min_damage(), on_damage(), itype::stack_size, and type.

Referenced by Character::armor_absorb(), iuse::gun_repair(), inc_damage(), activity_handlers::make_zlave_finish(), mod_damage(), vehicle::mod_hp(), and repair_item_actor::repair().

◆ mod_energy()

units::energy item::mod_energy ( const units::energy qty)

Add or remove energy from a battery.

If adding the specified energy quantity would go over the battery's capacity fill the battery and ignore the remainder. If adding the specified energy quantity would reduce the battery's charge level below 0 do nothing and return how far below 0 it would have gone.

Parameters
qtyenergy quantity to add (can be negative)
Returns
0 valued energy quantity on success

Definition at line 572 of file item.cpp.

573{
574 if( !is_battery() ) {
575 debugmsg( "Tried to set energy of non-battery item" );
576 return 0_J;
577 }
578
579 units::energy val = energy_remaining() + qty;
580 if( val < 0_J ) {
581 return val;
582 } else if( val > type->battery->max_capacity ) {
583 energy = type->battery->max_capacity;
584 } else {
585 energy = val;
586 }
587 return 0_J;
588}

References itype::battery, debugmsg, energy, energy_remaining(), is_battery(), and type.

◆ mod_last_rot_check()

void item::mod_last_rot_check ( time_duration  processing_duration)

This is part of a workaround so that items don't rot away to nothing if the smoking rack is outside the reality bubble.

Parameters
processing_duration

Definition at line 5721 of file item.cpp.

5722{
5723 if( !has_own_flag( "PROCESSING" ) ) {
5724 debugmsg( "mod_last_rot_check called on non smoking item: %s", tname() );
5725 return;
5726 }
5727
5728 // Apply no rot while smoking
5729 last_rot_check += processing_duration;
5730}

References debugmsg, has_own_flag(), last_rot_check, and tname().

◆ mod_rot()

void item::mod_rot ( const time_duration val)
inline

Definition at line 864 of file item.h.

864 {
865 rot += val;
866 }

◆ mutations_from_wearing()

std::vector< trait_id > item::mutations_from_wearing ( const Character guy) const

Definition at line 9076 of file item.cpp.

9077{
9078 if( !is_relic() ) {
9079 return std::vector<trait_id> {};
9080 }
9081 std::vector<trait_id> muts;
9082
9083 for( const enchantment &ench : relic_data->get_enchantments() ) {
9084 for( const trait_id &mut : ench.get_mutations() ) {
9085 // this may not be perfectly accurate due to conditions
9086 muts.push_back( mut );
9087 }
9088 }
9089
9090 for( const trait_id &char_mut : guy.get_mutations() ) {
9091 for( auto iter = muts.begin(); iter != muts.end(); ) {
9092 if( char_mut == *iter ) {
9093 iter = muts.erase( iter );
9094 } else {
9095 ++iter;
9096 }
9097 }
9098 }
9099
9100 return muts;
9101}
std::vector< trait_id > get_mutations(bool include_hidden=true) const
Get the idents of all traits/mutations.

References Character::get_mutations(), is_relic(), and relic_data.

Referenced by Character::on_item_takeoff(), and Character::on_item_wear().

◆ needs_processing()

bool item::needs_processing ( ) const

Whether the item should be processed (by calling process).

Definition at line 8935 of file item.cpp.

8936{
8939 is_artifact() || is_food();
8940}
bool needs_processing() const
Whether the item should be processed (by calling process).
Definition: item.cpp:8935
bool is_artifact() const
Definition: item.cpp:6968
static const std::string flag_ETHEREAL_ITEM("ETHEREAL_ITEM")

References active, contents, item_contents::empty(), flag_ETHEREAL_ITEM(), flag_RADIO_ACTIVATION(), item_contents::front(), has_flag(), is_artifact(), is_container(), is_food(), and needs_processing().

Referenced by map::add_item(), vehicle::add_item(), submap::load(), map::make_active(), vehicle::make_active(), needs_processing(), liquid_handler::perform_liquid_transfer(), and Character::process_items().

◆ nname()

std::string item::nname ( const itype_id id,
unsigned int  quantity = 1 
)
static

Returns the translated item name for the item with given id.

The name is in the proper plural form as specified by the quantity parameter. This is roughly equivalent to creating an item instance and calling tname, however this function does not include strings like "(fresh)".

Definition at line 9922 of file item.cpp.

9923{
9924 return id->nname( quantity );
9925}

Referenced by act_vehicle_unload_fuel(), ammo_info(), veh_interact::calc_overview(), camp_car_description(), crafting::can_disassemble(), Character::can_eat(), player::craft_consume_tools(), harvest_list::describe(), veh_interact::display_details(), draw_caravan_items(), spellcasting_callback::draw_spell_info(), farm_action(), activity_handlers::fertilize_plot_do_turn(), final_info(), iexamine::fvat_empty(), plot_options::get_descriptions(), iexamine::get_seed_entries(), plot_options::get_zone_name_suggestion(), repair_item_actor::handle_components(), ammobelt_actor::info(), iexamine::keg(), ma_style_callback::key(), lcmatch_any(), mill_load_food(), iuse::multicooker(), vpart_info::name(), comp_selection< CompType >::nname(), parse_tags(), peek_related_recipe(), activity_handlers::plant_seed_finish(), iexamine::portable_structure(), iexamine::pour_into_keg(), vehicle::print_fuel_indicator(), vehicle::print_part_list(), iexamine::quern_examine(), crafting::query_tool_selection(), avatar_action::reload(), activity_handlers::repair_item_finish(), recipe::result_name(), vehicle::select_engine(), player::select_item_component(), talk_effect_fun_t::set_u_sell_item(), character_funcs::siphon(), smoker_load_food(), iexamine::smoker_options(), vehicle::start_engine(), tname(), tool_comp::to_string(), iexamine::tree_maple(), iexamine::tree_maple_tapped(), try_consume(), unfold_vehicle_iuse::use(), consume_drug_iuse::use(), sew_advanced_actor::use(), and vehicle::use_washing_machine().

◆ on_contents_changed()

void item::on_contents_changed ( )

◆ on_damage()

void item::on_damage ( int  qty,
damage_type  dt 
)

Callback immediately before an item is damaged.

Parameters
qtymaximum damage that will be applied (constrained by max_damage)
dttype of damage (or DT_NULL)

Definition at line 4547 of file item.cpp.

4548{
4549 if( is_corpse() && qty + damage_ >= max_damage() ) {
4551 }
4552}

References damage_, flag_PULPED(), is_corpse(), max_damage(), and set_flag().

Referenced by mod_damage(), and set_damage().

◆ on_drop() [1/2]

bool item::on_drop ( const tripoint pos)

Invokes item type's itype::drop_action.

This function can change the item.

Parameters
posWhere is the item being placed. Note: the item isn't there yet.
Returns
true if the item was destroyed during placement.

Definition at line 9987 of file item.cpp.

9988{
9989 return on_drop( pos, get_map() );
9990}
bool on_drop(const tripoint &pos)
Invokes item type's itype::drop_action.
Definition: item.cpp:9987

References get_map(), and on_drop().

Referenced by map::add_item_or_charges(), and on_drop().

◆ on_drop() [2/2]

bool item::on_drop ( const tripoint pos,
map map 
)

Invokes item type's itype::drop_action.

This function can change the item.

Parameters
posWhere is the item being placed. Note: the item isn't there yet.
mapA map object associated with that position.
Returns
true if the item was destroyed during placement.

Definition at line 9992 of file item.cpp.

9993{
9994 // dropping liquids, even currently frozen ones, on the ground makes them
9995 // dirty
9996 if( made_of( LIQUID ) && !m.has_flag( flag_LIQUIDCONT, pos ) &&
9997 !has_own_flag( "DIRTY" ) ) {
9998 set_flag( "DIRTY" );
9999 }
10000 avatar &you = get_avatar();
10001 you.flag_encumbrance();
10002 return type->drop_action && type->drop_action.call( you, *this, false, pos );
10003}
void flag_encumbrance()
Flag encumbrance for updating.
Definition: character.cpp:1757
static const std::string flag_LIQUIDCONT("LIQUIDCONT")
use_function drop_action
Action to take BEFORE the item is placed on map.
Definition: itype.h:928
int call(player &, item &, bool, const tripoint &) const
Definition: iuse.cpp:9863

References use_function::call(), itype::drop_action, Character::flag_encumbrance(), flag_LIQUIDCONT(), get_avatar(), map::has_flag(), has_own_flag(), LIQUID, made_of(), set_flag(), and type.

◆ on_pickup()

void item::on_pickup ( Character p)

Callback when a player starts carrying the item.

The item is already in the inventory and is called from there. This is not called when the item is added to the inventory from worn vector or weapon slot. The item is considered already carried.

Definition at line 4516 of file item.cpp.

4517{
4518 // Fake characters are used to determine pickup weight and volume
4519 if( p.is_fake() ) {
4520 return;
4521 }
4522 avatar &you = get_avatar();
4523 // TODO: artifacts currently only work with the player character
4524 if( &p == &you && type->artifact ) {
4525 g->add_artifact_messages( type->artifact->effects_carried );
4526 }
4527 // if game is loaded - don't want ownership assigned during char creation
4528 if( you.getID().is_valid() ) {
4530 }
4531 if( is_bucket_nonempty() ) {
4533 }
4534
4535 p.flag_encumbrance();
4536}
virtual bool is_fake() const
Returns true for non-real Creatures used temporarily; i.e.
Definition: creature.cpp:978
bool is_valid() const
Definition: character_id.h:19
bool spill_contents(const tripoint &pos)
void handle_pickup_ownership(Character &c)
Definition: item.cpp:4476
bool is_bucket_nonempty() const
Definition: item.cpp:6745

References itype::artifact, contents, Character::flag_encumbrance(), g, get_avatar(), Character::getID(), handle_pickup_ownership(), is_bucket_nonempty(), Creature::is_fake(), character_id::is_valid(), Character::pos(), item_contents::spill_contents(), and type.

Referenced by Character::i_add().

◆ on_takeoff()

void item::on_takeoff ( Character p)

Callback when a character takes off an item.

The item is still in the worn items vector but will be removed immediately after the function returns

Definition at line 4395 of file item.cpp.

4396{
4397 p.on_item_takeoff( *this );
4398
4399 if( is_sided() ) {
4401 }
4402
4403 // if power armor, no power_draw and active, shut down.
4404 if( type->can_use( "set_transformed" ) && active ) {
4405 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
4406 ( this->get_use( "set_transformed" )->get_actor_ptr() );
4407 if( actor == nullptr ) {
4408 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
4409 return;
4410 }
4411 actor->bypass( *p.as_player(), *this, false, p.pos() );
4412 }
4413}
void on_item_takeoff(const item &it)
Called when an item is taken off.
Definition: character.cpp:9849
virtual player * as_player()
Definition: creature.h:122
bool set_side(side s)
Change the side on which the item is worn.
Definition: item.cpp:815
This is a iuse_transform used by items with transform dependencies.
Definition: iuse_actor.h:350
int bypass(player &p, item &it, bool t, const tripoint &pos) const
Hack: Bypasses normal checks to transform an item.
Definition: iuse_actor.cpp:985

References active, Creature::as_player(), BOTH, set_transformed_iuse::bypass(), itype::can_use(), debugmsg, use_function::get_actor_ptr(), get_use(), is_sided(), Character::on_item_takeoff(), Character::pos(), set_side(), and type.

Referenced by Character::absorb_hit(), Character::i_rem(), and starting_clothes().

◆ on_wear()

void item::on_wear ( Character p)

Callback when a character starts wearing the item.

The item is already in the worn items vector and is called from there.

Definition at line 4297 of file item.cpp.

4298{
4299 if( is_sided() && get_side() == side::BOTH ) {
4300 if( has_flag( flag_SPLINT ) ) {
4302 if( ( covers( bodypart_id( "leg_l" ) ) && p.is_limb_broken( bodypart_id( "leg_r" ) ) &&
4303 !p.worn_with_flag( flag_SPLINT, bodypart_id( "leg_r" ) ) ) ||
4304 ( covers( bodypart_id( "arm_l" ) ) && p.is_limb_broken( bodypart_id( "arm_r" ) ) &&
4305 !p.worn_with_flag( flag_SPLINT, bodypart_id( "arm_r" ) ) ) ) {
4307 }
4308 } else if( has_flag( flag_POWERARMOR_MOD ) ) {
4309 // for power armor mods, wear on side with least mods
4310 std::vector< std::pair< body_part, int > > mod_parts;
4311 body_part bp = num_bp;
4312 bodypart_str_id bpid;
4313 int lhs = 0;
4314 int rhs = 0;
4315 for( std::size_t i = 0; i < static_cast< body_part >( num_bp ) ; ++i ) {
4316 bp = static_cast< body_part >( i );
4317 if( get_covered_body_parts().test( bp ) ) {
4318 mod_parts.emplace_back( bp, 0 );
4319 }
4320 }
4321 for( auto &elem : p.worn ) {
4322 for( std::pair< body_part, int > &mod_part : mod_parts ) {
4323 bpid = convert_bp( mod_part.first );
4324 if( elem.get_covered_body_parts().test( mod_part.first ) &&
4325 elem.has_flag( flag_POWERARMOR_MOD ) ) {
4326 if( elem.is_sided() && elem.get_side() == bpid->part_side ) {
4327 mod_part.second++;
4328 continue;
4329 }
4330 mod_part.second++;
4331 }
4332 }
4333 }
4334 for( std::pair< body_part, int > &mod_part : mod_parts ) {
4335 bpid = convert_bp( mod_part.first );
4336 if( bpid->part_side == side::LEFT && mod_part.second > lhs ) {
4337 add_msg( _( "left" ) );
4338 lhs = mod_part.second;
4339 } else if( bpid->part_side == side::RIGHT && mod_part.second > rhs ) {
4340 add_msg( _( "right" ) );
4341 rhs = mod_part.second;
4342 }
4343 }
4344 set_side( ( lhs > rhs ) ? side::RIGHT : side::LEFT );
4345 } else {
4346 // for sided items wear the item on the side which results in least encumbrance
4347 int lhs = 0;
4348 int rhs = 0;
4350 const char_encumbrance_data left_enc = p.get_encumbrance( *this );
4351 for( const body_part bp : all_body_parts ) {
4352 lhs += left_enc.elems[bp].encumbrance;
4353 }
4354
4356 const char_encumbrance_data right_enc = p.get_encumbrance( *this );
4357 for( const body_part bp : all_body_parts ) {
4358 rhs += right_enc.elems[bp].encumbrance;
4359 }
4360
4361 set_side( lhs <= rhs ? side::LEFT : side::RIGHT );
4362 }
4363 }
4364
4365 if( type->can_use( "set_transformed" ) ) {
4366 bool transform = false;
4367 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
4368 ( this->get_use( "set_transformed" )->get_actor_ptr() );
4369 if( actor == nullptr ) {
4370 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
4371 return;
4372 }
4373 std::string transform_flag = actor->dependencies;
4374 for( const auto &elem : p.worn ) {
4375 if( elem.has_flag( transform_flag ) && elem.active != active ) {
4376 transform = true;
4377 }
4378 }
4379 if( transform && actor->restricted ) {
4380 actor->bypass( *p.as_player(), *this, false, p.pos() );
4381 }
4382 }
4383
4384 // TODO: artifacts currently only work with the player character
4385 if( &p == &get_avatar() && type->artifact ) {
4386 g->add_artifact_messages( type->artifact->effects_worn );
4387 }
4388 // if game is loaded - don't want ownership assigned during char creation
4389 if( get_avatar().getID().is_valid() ) {
4391 }
4392 p.on_item_wear( *this );
4393}
constexpr std::array< body_part, 12 > all_body_parts
Contains all valid body_part values in the order they are defined in.
Definition: bodypart.h:82
body_part
Definition: bodypart.h:39
@ num_bp
Definition: bodypart.h:52
bool worn_with_flag(const std::string &flag, const bodypart_id &bp=bodypart_str_id::NULL_ID()) const
Returns true if the player is wearing an item with the given flag.
Definition: character.cpp:3254
void on_item_wear(const item &it)
Called when an item is worn.
Definition: character.cpp:9834
bool is_limb_broken(const bodypart_id &limb) const
Returns true if the limb is broken.
Definition: character.cpp:1259
char_encumbrance_data get_encumbrance() const
Get encumbrance for all body parts.
Definition: character.cpp:3694
Just like the string_id, this is a wrapper for int based identifiers.
Definition: int_id.h:20
bool restricted
Whether the object can only be transformed externally.
Definition: iuse_actor.h:355
std::string dependencies
String defining flag needed on activating item.
Definition: iuse_actor.h:360
static const std::string flag_SPLINT("SPLINT")
void add_msg(std::string msg)
Definition: messages.cpp:910
side part_side
Definition: bodypart.h:126
std::array< encumbrance_data, num_bp > elems

References _, active, add_msg(), all_body_parts, itype::artifact, Creature::as_player(), BOTH, set_transformed_iuse::bypass(), itype::can_use(), convert_bp(), covers(), debugmsg, set_transformed_iuse::dependencies, char_encumbrance_data::elems, flag_POWERARMOR_MOD(), flag_SPLINT(), g, use_function::get_actor_ptr(), get_avatar(), get_covered_body_parts(), Character::get_encumbrance(), get_side(), get_use(), handle_pickup_ownership(), has_flag(), Character::is_limb_broken(), is_sided(), LEFT, num_bp, Character::on_item_wear(), body_part_type::part_side, Character::pos(), set_transformed_iuse::restricted, RIGHT, set_side(), body_part_set::test(), iexamine::transform(), type, Character::worn, and Character::worn_with_flag().

Referenced by starting_clothes().

◆ on_wield()

void item::on_wield ( player p,
int  mv = 0 
)

Callback when a player starts wielding the item.

The item is already in the weapon slot and is called from there.

Parameters
pplayer that has started wielding item
mvnumber of moves already spent wielding the weapon

Definition at line 4415 of file item.cpp.

4416{
4417 // TODO: artifacts currently only work with the player character
4418 if( &p == &get_avatar() && type->artifact ) {
4419 g->add_artifact_messages( type->artifact->effects_wielded );
4420 }
4421
4422 // weapons with bayonet/bipod or other generic "unhandiness"
4423 if( has_flag( flag_SLOW_WIELD ) && !is_gunmod() ) {
4424 float d = 32.0; // arbitrary linear scaling factor
4425 if( is_gun() ) {
4426 d /= std::max( p.get_skill_level( gun_skill() ), 1 );
4427 } else if( is_melee() ) {
4428 d /= std::max( p.get_skill_level( melee_skill() ), 1 );
4429 }
4430
4431 int penalty = get_var( "volume", volume() / units::legacy_volume_factor ) * d;
4432 p.moves -= penalty;
4433 mv += penalty;
4434 }
4435
4436 // firearms with a folding stock or tool/melee without collapse/retract iuse
4437 if( has_flag( flag_NEEDS_UNFOLD ) && !is_gunmod() ) {
4438 int penalty = 50; // 200-300 for guns, 50-150 for melee, 50 as fallback
4439 if( is_gun() ) {
4440 penalty = std::max( 0, 300 - p.get_skill_level( gun_skill() ) * 10 );
4441 } else if( is_melee() ) {
4442 penalty = std::max( 0, 150 - p.get_skill_level( melee_skill() ) * 10 );
4443 }
4444
4445 p.moves -= penalty;
4446 mv += penalty;
4447 }
4448
4449 std::string msg;
4450
4451 if( mv > 500 ) {
4452 msg = _( "It takes you an extremely long time to wield your %s." );
4453 } else if( mv > 250 ) {
4454 msg = _( "It takes you a very long time to wield your %s." );
4455 } else if( mv > 100 ) {
4456 msg = _( "It takes you a long time to wield your %s." );
4457 } else if( mv > 50 ) {
4458 msg = _( "It takes you several seconds to wield your %s." );
4459 } else {
4460 msg = _( "You wield your %s." );
4461 }
4462 // if game is loaded - don't want ownership assigned during char creation
4463 if( p.getID().is_valid() ) {
4465 }
4466 p.add_msg_if_player( m_neutral, msg, tname() );
4467
4468 if( !p.martial_arts_data->selected_is_none() ) {
4469 p.martial_arts_data->martialart_use_message( p );
4470 }
4471
4472 // Update encumbrance in case we were wearing it
4473 p.flag_encumbrance();
4474}
int moves
Definition: creature.h:582
void add_msg_if_player(const std::string &msg) const override
Definition: player.cpp:364
@ m_neutral
Definition: enums.h:267
static const std::string flag_NEEDS_UNFOLD("NEEDS_UNFOLD")
static const std::string flag_SLOW_WIELD("SLOW_WIELD")

References _, player::add_msg_if_player(), itype::artifact, Character::flag_encumbrance(), flag_NEEDS_UNFOLD(), flag_SLOW_WIELD(), g, get_avatar(), Character::get_skill_level(), get_var(), Character::getID(), gun_skill(), handle_pickup_ownership(), has_flag(), is_gun(), is_gunmod(), is_melee(), character_id::is_valid(), units::legacy_volume_factor, m_neutral, Character::martial_arts_data, melee_skill(), Creature::moves, tname(), type, and volume().

Referenced by character_funcs::try_wield_contents(), and avatar::wield().

◆ only_made_of()

bool item::only_made_of ( const std::set< material_id > &  mat_idents) const

Check we are made of only the materials (e.g.

false if we have one material not in the set or no materials at all).

Parameters
mat_identsSet of material ids.

Definition at line 6447 of file item.cpp.

6448{
6449 const std::vector<material_id> &mats = made_of();
6450 if( mats.empty() ) {
6451 return false;
6452 }
6453
6454 return std::all_of( mats.begin(), mats.end(), [&mat_idents]( const material_id & e ) {
6455 return mat_idents.count( e );
6456 } );
6457}

References made_of().

Referenced by salvage_actor::try_to_cut_up(), and salvage_actor::valid_to_cut_up().

◆ operator<()

bool item::operator< ( const item other) const

Definition at line 7157 of file item.cpp.

7158{
7159 const item_category &cat_a = get_category();
7160 const item_category &cat_b = other.get_category();
7161 if( cat_a != cat_b ) {
7162 return cat_a < cat_b;
7163 } else {
7164 const item *me = is_container() && !contents.empty() ? &contents.front() : this;
7165 const item *rhs = other.is_container() &&
7166 !other.contents.empty() ? &other.contents.front() : &other;
7167
7168 const itype *me_type = me->type;
7169 const itype *rhs_type = rhs->type;
7170 if( !me_type || !rhs_type ) {
7171 return !!me_type;
7172 }
7173
7174 if( me_type->get_id() == rhs_type->get_id() ) {
7175 if( me->is_money() ) {
7176 return me->charges > rhs->charges;
7177 }
7178 return me->charges < rhs->charges;
7179 } else {
7180 std::string n1 = me_type->nname( 1 );
7181 std::string n2 = rhs_type->nname( 1 );
7182 return localized_compare( n1, n2 );
7183 }
7184 }
7185}

References charges, contents, item_contents::empty(), item_contents::front(), get_category(), itype::get_id(), is_container(), is_money(), localized_compare, itype::nname(), other, and type.

◆ operator=() [1/2]

item & item::operator= ( const item )
default

◆ operator=() [2/2]

item & item::operator= ( item &&  )
default

◆ price()

int item::price ( bool  practical) const

Returns the monetary value of an item.

If practical is false, returns pre-cataclysm market value, otherwise returns approximate post-cataclysm value.

Definition at line 4921 of file item.cpp.

4922{
4923 int res = 0;
4924
4925 visit_items( [&res, practical]( const item * e ) {
4926 if( e->rotten() ) {
4927 // TODO: Special case things that stay useful when rotten
4928 return VisitResponse::NEXT;
4929 }
4930
4931 int child = units::to_cent( practical ? e->type->price_post : e->type->price );
4932 if( e->damage() > 0 ) {
4933 // maximal damage level is 4, maximal reduction is 40% of the value.
4934 child -= child * static_cast<double>( e->damage_level( 4 ) ) / 10;
4935 }
4936
4937 if( e->count_by_charges() || e->made_of( LIQUID ) ) {
4938 // price from json data is for default-sized stack
4939 child *= e->charges / static_cast<double>( e->type->stack_size );
4940
4941 } else if( e->magazine_integral() && e->ammo_remaining() && e->ammo_data() ) {
4942 // items with integral magazines may contain ammunition which can affect the price
4943 child += item( e->ammo_data(), calendar::turn, e->charges ).price( practical );
4944
4945 } else if( e->is_tool() && e->ammo_types().empty() && e->ammo_capacity() ) {
4946 // if tool has no ammo (e.g. spray can) reduce price proportional to remaining charges
4947 child *= e->ammo_remaining() / static_cast<double>( std::max( e->type->charges_default(), 1 ) );
4948 }
4949
4950 res += child;
4951 return VisitResponse::NEXT;
4952 } );
4953
4954 return res;
4955}
constexpr value_type to_cent(const quantity< value_type, money_in_cent_tag > &v)
Definition: units_money.h:44
units::money price
Value before cataclysm.
Definition: itype.h:985
units::money price_post
Value after cataclysm, dependent upon practical usages.
Definition: itype.h:987

References ammo_capacity(), ammo_data(), ammo_remaining(), ammo_types(), count_by_charges(), damage(), is_tool(), LIQUID, made_of(), magazine_integral(), NEXT, itype::price, itype::price_post, rotten(), units::to_cent(), type, and visitable< item >::visit_items().

Referenced by talk_function::bionic_install(), talk_function::bionic_remove(), defense_game::caravan(), draw_caravan_items(), talk_function::field_harvest(), final_info(), bionic_install_surgeon_preset::get_money_amount(), npc_trading::init_buying(), npc_trading::init_selling(), parse_tags(), talk_effect_fun_t::set_bulk_trade_accept(), npc::shop_restock(), npc::value(), npc::wants_to_buy(), and npc::wants_to_sell().

◆ process() [1/2]

bool item::process ( player carrier,
const tripoint pos,
bool  activate,
temperature_flag  flag,
const weather_manager weather_generator 
)

Definition at line 9597 of file item.cpp.

9599{
9600 const bool preserves = type->container && type->container->preserves;
9601 const bool seals = type->container && type->container->seals;
9602 std::vector<item *> removed_items;
9603 visit_items( [&]( item * it ) {
9604 if( preserves ) {
9605 // Simulate that the item has already "rotten" up to last_rot_check, but as item::rot
9606 // is not changed, the item is still fresh.
9608 }
9609 if( it->process_internal( carrier, pos, activate, seals, flag, weather_generator ) ) {
9610 removed_items.push_back( it );
9611 }
9612 return VisitResponse::NEXT;
9613 } );
9614 for( item *it : removed_items ) {
9615 if( it != this ) {
9616 remove_item( *it );
9617 }
9618 }
9619 return !removed_items.empty() && std::any_of( removed_items.begin(), removed_items.end(),
9620 [this]( const item * r ) {
9621 return r == this;
9622 } );
9623}
bool process_internal(player *carrier, const tripoint &pos, bool activate, bool seals, temperature_flag flag, const weather_manager &weather_generator)
Definition: item.cpp:9625
item & activate()
Filter converting instance to active state.
Definition: item.cpp:557

References activate(), itype::container, last_rot_check, NEXT, process_internal(), visitable< item >::remove_item(), calendar::turn, type, and visitable< item >::visit_items().

◆ process() [2/2]

bool item::process ( player carrier,
const tripoint pos,
bool  activate,
temperature_flag  flag = temperature_flag::TEMP_NORMAL 
)

This is called once each turn.

It's usually only useful for active items, but can be called for inactive items without problems. It is recursive, and calls process on any contained items.

Parameters
carrierThe player / npc that carries the item. This can be null when the item is not carried by anyone (laying on ground)!
posThe location of the item on the map, same system as player::pos used. If the item is carried, it should be the location of the carrier.
activateWhether the item should be activated (true), or processed as an active item.
Returns
true if the item has been destroyed by the processing. The caller should than delete the item wherever it was stored. Returns false if the item is not destroyed.

Definition at line 9591 of file item.cpp.

9593{
9594 return process( carrier, pos, activate, flag, get_weather() );
9595}
bool process(player *carrier, const tripoint &pos, bool activate, temperature_flag flag=temperature_flag::TEMP_NORMAL)
This is called once each turn.
Definition: item.cpp:9591
weather_manager & get_weather()
Definition: weather.cpp:64

References activate(), get_weather(), and process().

Referenced by map::add_item(), iuse::cable_attach(), drop_or_embed_projectile(), mattack::kamikaze(), process(), vehicle_part::process_contents(), Character::process_items(), and iuse::tow_attach().

◆ process_artifact()

void item::process_artifact ( player carrier,
const tripoint pos 
)

Process and apply artifact effects.

This should be called exactly once each turn, it may modify character stats (like speed, strength, ...), so call it after those have been reset.

Parameters
carrierThe character carrying the artifact, can be null.
posThe location of the artifact (should be the player location if carried).

Definition at line 9061 of file item.cpp.

9062{
9063 if( !is_artifact() ) {
9064 return;
9065 }
9066 // Artifacts are currently only useful for the player character, the messages
9067 // don't consider npcs. Also they are not processed when laying on the ground.
9068 // TODO: change game::process_artifact to work with npcs,
9069 // TODO: consider moving game::process_artifact here.
9070 if( carrier == &get_avatar() ) {
9071 g->process_artifact( *this, *carrier );
9072 }
9073}

References g, get_avatar(), and is_artifact().

Referenced by Character::process_turn().

◆ process_blackpowder_fouling()

bool item::process_blackpowder_fouling ( player carrier)
protected

Definition at line 9580 of file item.cpp.

9581{
9582 if( damage() < max_damage() && one_in( 2000 ) ) {
9584 if( carrier ) {
9585 carrier->add_msg_if_player( m_bad, _( "Your %s rusts due to blackpowder fouling." ), tname() );
9586 }
9587 }
9588 return false;
9589}
@ m_bad
Definition: enums.h:261

References _, player::add_msg_if_player(), damage(), DT_ACID, inc_damage(), m_bad, max_damage(), one_in(), and tname().

Referenced by process_internal().

◆ process_cable()

bool item::process_cable ( player carrier,
const tripoint pos 
)
protected

Definition at line 9362 of file item.cpp.

9363{
9364 if( carrier == nullptr ) {
9365 //reset_cable( carrier );
9366 return false;
9367 }
9368 std::string state = get_var( "state" );
9369 if( state == "solar_pack_link" || state == "solar_pack" ) {
9370 if( !carrier->has_item( *this ) || !carrier->worn_with_flag( "SOLARPACK_ON" ) ) {
9371 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9372 reset_cable( carrier );
9373 return false;
9374 }
9375 }
9376
9377 static const item_filter used_ups = [&]( const item & itm ) {
9378 return itm.get_var( "cable" ) == "plugged_in";
9379 };
9380
9381 if( state == "UPS" ) {
9382 if( !carrier->has_item( *this ) || !carrier->has_item_with( used_ups ) ) {
9383 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9384 for( item *used : carrier->items_with( used_ups ) ) {
9385 used->erase_var( "cable" );
9386 }
9387 reset_cable( carrier );
9388 return false;
9389 }
9390 }
9391 const std::optional<tripoint> source = get_cable_target( carrier, pos );
9392 if( !source ) {
9393 return false;
9394 }
9395 map &here = get_map();
9396 if( !here.veh_at( *source ) || ( source->z != g->get_levz() && !here.has_zlevels() ) ) {
9397 if( carrier->has_item( *this ) ) {
9398 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9399 }
9400 reset_cable( carrier );
9401 return false;
9402 }
9403
9404 int distance = rl_dist( pos, *source );
9405 int max_charges = type->maximum_charges();
9406 charges = max_charges - distance;
9407
9408 if( charges < 1 ) {
9409 if( carrier->has_item( *this ) ) {
9410 carrier->add_msg_if_player( m_bad, _( "The over-extended cable breaks loose!" ) );
9411 }
9412 reset_cable( carrier );
9413 }
9414
9415 return false;
9416}
void reset_cable(player *p)
Helper to bring a cable back to its initial state.
Definition: item.cpp:9418
std::optional< tripoint > get_cable_target(Character *p, const tripoint &pos) const
Gets the point (vehicle tile) the cable is connected to.
Definition: item.cpp:9342
bool has_zlevels() const
Definition: map.h:1635
std::vector< item * > items_with(const std::function< bool(const item &)> &filter)
Returns all items (including those within a container) matching the filter.
Definition: visitable.cpp:324
std::function< bool(const item &)> item_filter
Definition: game.h:119
int maximum_charges() const
Definition: itype.cpp:123

References _, player::add_msg_if_player(), charges, g, get_cable_target(), get_map(), get_var(), visitable< T >::has_item(), visitable< T >::has_item_with(), map::has_zlevels(), visitable< T >::items_with(), m_bad, itype::maximum_charges(), reset_cable(), rl_dist(), type, map::veh_at(), and Character::worn_with_flag().

Referenced by process_internal().

◆ process_corpse()

bool item::process_corpse ( player carrier,
const tripoint pos 
)
protected

Definition at line 9119 of file item.cpp.

9120{
9121 // some corpses rez over time
9122 if( corpse == nullptr || damage() >= max_damage() ) {
9123 return false;
9124 }
9125 if( corpse->zombify_into && rotten() ) {
9126 rot -= get_shelf_life();
9128 return false;
9129 }
9130 if( !ready_to_revive( pos ) ) {
9131 return false;
9132 }
9133 if( rng( 0, volume() / units::legacy_volume_factor ) > burnt && g->revive_corpse( pos, *this ) ) {
9134 if( carrier == nullptr ) {
9135 if( get_avatar().sees( pos ) ) {
9136 if( corpse->in_species( ROBOT ) ) {
9137 add_msg( m_warning, _( "A nearby robot has repaired itself and stands up!" ) );
9138 } else {
9139 add_msg( m_warning, _( "A nearby corpse rises and moves towards you!" ) );
9140 }
9141 }
9142 } else {
9143 if( corpse->in_species( ROBOT ) ) {
9144 carrier->add_msg_if_player( m_warning,
9145 _( "Oh dear god, a robot you're carrying has started moving!" ) );
9146 } else {
9147 carrier->add_msg_if_player( m_warning,
9148 _( "Oh dear god, a corpse you're carrying has started moving!" ) );
9149 }
9150 }
9151 // Destroy this corpse item
9152 return true;
9153 }
9154
9155 return false;
9156}
bool ready_to_revive(const tripoint &pos) const
Whether this corpse should revive now.
Definition: item.cpp:5965
@ m_warning
Definition: enums.h:264
static const species_id ROBOT("ROBOT")
mtype_id zombify_into
Definition: mtype.h:332
bool in_species(const species_id &spec) const
Definition: mtype.cpp:122

References _, add_msg(), player::add_msg_if_player(), burnt, corpse, damage(), g, get_avatar(), get_shelf_life(), mtype::in_species(), units::legacy_volume_factor, m_warning, max_damage(), ready_to_revive(), rng(), ROBOT, rotten(), volume(), and mtype::zombify_into.

Referenced by process_internal().

◆ process_extinguish()

bool item::process_extinguish ( player carrier,
const tripoint pos 
)
protected

Definition at line 9267 of file item.cpp.

9268{
9269 // checks for water
9270 bool extinguish = false;
9271 bool in_inv = carrier != nullptr && carrier->has_item( *this );
9272 bool submerged = false;
9273 bool precipitation = false;
9274 bool windtoostrong = false;
9275 bool in_veh = carrier != nullptr && carrier->in_vehicle;
9276 int windpower = get_weather().windspeed;
9277 switch( get_weather().weather_id->precip ) {
9279 precipitation = one_in( 100 );
9280 break;
9282 precipitation = one_in( 50 );
9283 break;
9285 precipitation = one_in( 10 );
9286 break;
9287 default:
9288 break;
9289 }
9290 map &here = get_map();
9291 if( in_inv && !in_veh && here.has_flag( flag_DEEP_WATER, pos ) ) {
9292 extinguish = true;
9293 submerged = true;
9294 }
9295 if( ( !in_inv && here.has_flag( flag_LIQUID, pos ) && !here.veh_at( pos ) ) ||
9296 ( precipitation && !g->is_sheltered( pos ) ) ) {
9297 extinguish = true;
9298 }
9299 if( in_inv && windpower > 5 && !g->is_sheltered( pos ) &&
9300 this->has_flag( flag_WIND_EXTINGUISH ) ) {
9301 windtoostrong = true;
9302 extinguish = true;
9303 }
9304 if( !extinguish ||
9305 ( in_inv && precipitation && carrier->primary_weapon().has_flag( flag_RAIN_PROTECT ) ) ) {
9306 return false; //nothing happens
9307 }
9308 if( carrier != nullptr ) {
9309 if( submerged ) {
9310 carrier->add_msg_if_player( m_neutral, _( "Your %s is quenched by water." ), tname() );
9311 } else if( precipitation ) {
9312 carrier->add_msg_if_player( m_neutral, _( "Your %s is quenched by precipitation." ),
9313 tname() );
9314 } else if( windtoostrong ) {
9315 carrier->add_msg_if_player( m_neutral, _( "Your %s is blown out by the wind." ),
9316 tname() );
9317 }
9318 }
9319
9320 // cig dies out
9321 if( has_flag( flag_LITCIG ) ) {
9322 if( typeId() == itype_cig_lit ) {
9324 } else if( typeId() == itype_cigar_lit ) {
9326 } else { // joint
9328 }
9329 } else { // transform (lit) items
9330 if( type->tool->revert_to ) {
9331 convert( *type->tool->revert_to );
9332 } else {
9333 type->invoke( carrier != nullptr ? *carrier : get_avatar(), *this, pos, "transform" );
9334 }
9335
9336 }
9337 active = false;
9338 // Item remains
9339 return false;
9340}
bool in_vehicle
Definition: character.h:1568
item & primary_weapon()
Legacy code hack, don't use.
Definition: melee.cpp:154
bool has_flag(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2374
static const itype_id itype_cigar_butt("cigar_butt")
static const itype_id itype_joint_roach("joint_roach")
static const itype_id itype_cig_butt("cig_butt")
static const std::string flag_LIQUID("LIQUID")
static const std::string flag_DEEP_WATER("DEEP_WATER")
static const itype_id itype_cigar_lit("cigar_lit")
static const std::string flag_WIND_EXTINGUISH("WIND_EXTINGUISH")
static const std::string flag_RAIN_PROTECT("RAIN_PROTECT")
static const itype_id itype_cig_lit("cig_lit")
int invoke(player &p, item &it, const tripoint &pos) const
Definition: itype.cpp:180

References _, active, player::add_msg_if_player(), convert(), flag_DEEP_WATER(), flag_LIQUID(), flag_LITCIG(), flag_RAIN_PROTECT(), flag_WIND_EXTINGUISH(), g, get_avatar(), get_map(), get_weather(), has_flag(), map::has_flag(), visitable< T >::has_item(), heavy, Character::in_vehicle, itype::invoke(), itype_cig_butt, itype_cig_lit, itype_cigar_butt, itype_cigar_lit, itype_joint_roach, light, m_neutral, one_in(), Character::primary_weapon(), tname(), itype::tool, type, typeId(), map::veh_at(), very_light, and weather_manager::windspeed.

Referenced by process_internal(), and process_litcig().

◆ process_fake_mill()

bool item::process_fake_mill ( player carrier,
const tripoint pos 
)
protected

Definition at line 9158 of file item.cpp.

9159{
9160 map &here = get_map();
9161 if( here.furn( pos ) != furn_str_id( "f_wind_mill_active" ) &&
9162 here.furn( pos ) != furn_str_id( "f_water_mill_active" ) ) {
9163 item_counter = 0;
9164 return true; //destroy fake mill
9165 }
9166 if( age() >= 6_hours || item_counter == 0 ) {
9168 birthday() ); //activate effects when timers goes to zero
9169 return true; //destroy fake mill item
9170 }
9171
9172 return false;
9173}
furn_id furn(const tripoint &p) const
Definition: map.cpp:1412
void mill_finalize(player &, const tripoint &examp, const time_point &start_time)
Definition: iexamine.cpp:5469

References age(), birthday(), map::furn(), get_avatar(), get_map(), item_counter, and iexamine::mill_finalize().

Referenced by process_internal().

◆ process_fake_smoke()

bool item::process_fake_smoke ( player carrier,
const tripoint pos 
)
protected

Definition at line 9175 of file item.cpp.

9176{
9177 map &here = get_map();
9178 if( here.furn( pos ) != furn_str_id( "f_smoking_rack_active" ) &&
9179 here.furn( pos ) != furn_str_id( "f_metal_smoking_rack_active" ) ) {
9180 item_counter = 0;
9181 return true; //destroy fake smoke
9182 }
9183
9184 if( age() >= 6_hours || item_counter == 0 ) {
9185 iexamine::on_smoke_out( pos, birthday() ); //activate effects when timers goes to zero
9186 return true; //destroy fake smoke when it 'burns out'
9187 }
9188
9189 return false;
9190}
void on_smoke_out(const tripoint &examp, const time_point &start_time)
Definition: iexamine.cpp:5785

References age(), birthday(), map::furn(), get_map(), item_counter, and iexamine::on_smoke_out().

Referenced by process_internal().

◆ process_internal()

bool item::process_internal ( player carrier,
const tripoint pos,
bool  activate,
bool  seals,
temperature_flag  flag,
const weather_manager weather_generator 
)
private

Definition at line 9625 of file item.cpp.

9628{
9629 if( has_flag( flag_ETHEREAL_ITEM ) ) {
9630 if( !has_var( "ethereal" ) ) {
9631 return true;
9632 }
9633 set_var( "ethereal", std::stoi( get_var( "ethereal" ) ) - 1 );
9634 const bool processed = std::stoi( get_var( "ethereal" ) ) <= 0;
9635 if( processed && carrier != nullptr ) {
9636 carrier->add_msg_if_player( _( "Your %s disappears!" ), tname() );
9637 }
9638 return processed;
9639 }
9640
9641 if( faults.count( fault_gun_blackpowder ) ) {
9642 return process_blackpowder_fouling( carrier );
9643 }
9644
9645 avatar &you = get_avatar();
9646 if( activate ) {
9647 return type->invoke( carrier != nullptr ? *carrier : you, *this, pos );
9648 }
9649 // How this works: it checks what kind of processing has to be done
9650 // (e.g. for food, for drying towels, lit cigars), and if that matches,
9651 // call the processing function. If that function returns true, the item
9652 // has been destroyed by the processing, so no further processing has to be
9653 // done.
9654 // Otherwise processing continues. This allows items that are processed as
9655 // food and as litcig and as ...
9656
9657 // Remaining stuff is only done for active items.
9658 if( !active ) {
9659 return false;
9660 }
9661
9662 if( !is_food() && item_counter > 0 ) {
9663 item_counter--;
9664 }
9665
9666 if( item_counter == 0 && type->countdown_action ) {
9667 type->countdown_action.call( carrier ? *carrier : you, *this, false, pos );
9668 if( type->countdown_destroy ) {
9669 return true;
9670 }
9671 }
9672
9673 map &here = get_map();
9674 for( const emit_id &e : type->emits ) {
9675 here.emit_field( pos, e );
9676 }
9677
9678 if( has_flag( flag_FAKE_SMOKE ) && process_fake_smoke( carrier, pos ) ) {
9679 return true;
9680 }
9681 if( has_flag( flag_FAKE_MILL ) && process_fake_mill( carrier, pos ) ) {
9682 return true;
9683 }
9684 if( is_corpse() && process_corpse( carrier, pos ) ) {
9685 return true;
9686 }
9687 if( has_flag( flag_WET ) && process_wet( carrier, pos ) ) {
9688 // Drying items are never destroyed, but we want to exit so they don't get processed as tools.
9689 return false;
9690 }
9691 if( has_flag( flag_LITCIG ) && process_litcig( carrier, pos ) ) {
9692 return true;
9693 }
9695 process_extinguish( carrier, pos ) ) {
9696 return false;
9697 }
9698 if( has_flag( flag_CABLE_SPOOL ) ) {
9699 // DO NOT process this as a tool! It really isn't!
9700 return process_cable( carrier, pos );
9701 }
9702 if( has_flag( flag_IS_UPS ) ) {
9703 // DO NOT process this as a tool! It really isn't!
9704 return process_UPS( carrier, pos );
9705 }
9706 if( is_tool() ) {
9707 return process_tool( carrier, pos );
9708 }
9709 // All foods that go bad have temperature
9710 if( ( is_food() || is_corpse() ) &&
9711 process_rot( seals, pos, carrier, flag, weather_generator ) ) {
9712 if( is_comestible() ) {
9713 here.rotten_item_spawn( *this, pos );
9714 }
9715 return true;
9716 }
9717
9718 return false;
9719}
bool process_fake_mill(player *carrier, const tripoint &pos)
Definition: item.cpp:9158
bool process_UPS(player *carrier, const tripoint &pos)
Definition: item.cpp:9435
bool process_corpse(player *carrier, const tripoint &pos)
Definition: item.cpp:9119
bool process_wet(player *carrier, const tripoint &pos)
Definition: item.cpp:9453
bool process_blackpowder_fouling(player *carrier)
Definition: item.cpp:9580
bool process_litcig(player *carrier, const tripoint &pos)
Definition: item.cpp:9192
bool process_extinguish(player *carrier, const tripoint &pos)
Definition: item.cpp:9267
bool process_fake_smoke(player *carrier, const tripoint &pos)
Definition: item.cpp:9175
bool process_tool(player *carrier, const tripoint &pos)
Definition: item.cpp:9466
bool process_cable(player *carrier, const tripoint &pos)
Definition: item.cpp:9362
void emit_field(const tripoint &pos, const emit_id &src, float mul=1.0f)
Runs one cycle of emission src which may result in propagation of fields.
Definition: map_field.cpp:1927
void rotten_item_spawn(const item &item, const tripoint &p)
Checks to see if the item that is rotting away generates a creature when it does.
Definition: map.cpp:7214
static const std::string flag_WATER_EXTINGUISH("WATER_EXTINGUISH")
static const std::string flag_CABLE_SPOOL("CABLE_SPOOL")
static const fault_id fault_gun_blackpowder("fault_gun_blackpowder")
static const std::string flag_IS_UPS("IS_UPS")
static const std::string flag_FAKE_MILL("FAKE_MILL")
static const std::string flag_FAKE_SMOKE("FAKE_SMOKE")
use_function countdown_action
Action to take when countdown expires.
Definition: itype.h:956
bool countdown_destroy
Is item destroyed after the countdown action is run?
Definition: itype.h:950
std::set< emit_id > emits
Fields to emit when item is in active state.
Definition: itype.h:931

References _, activate(), active, player::add_msg_if_player(), use_function::call(), itype::countdown_action, itype::countdown_destroy, map::emit_field(), itype::emits, fault_gun_blackpowder, faults, flag_CABLE_SPOOL(), flag_ETHEREAL_ITEM(), flag_FAKE_MILL(), flag_FAKE_SMOKE(), flag_IS_UPS(), flag_LITCIG(), flag_WATER_EXTINGUISH(), flag_WET(), flag_WIND_EXTINGUISH(), get_avatar(), get_map(), get_var(), has_flag(), has_var(), itype::invoke(), is_comestible(), is_corpse(), is_food(), is_tool(), item_counter, process_blackpowder_fouling(), process_cable(), process_corpse(), process_extinguish(), process_fake_mill(), process_fake_smoke(), process_litcig(), process_rot(), process_tool(), process_UPS(), process_wet(), map::rotten_item_spawn(), set_var(), tname(), and type.

Referenced by process().

◆ process_litcig()

bool item::process_litcig ( player carrier,
const tripoint pos 
)
protected

Definition at line 9192 of file item.cpp.

9193{
9194 if( !one_in( 10 ) ) {
9195 return false;
9196 }
9197 process_extinguish( carrier, pos );
9198 // process_extinguish might have extinguished the item already
9199 if( !active ) {
9200 return false;
9201 }
9202 map &here = get_map();
9203 // if carried by someone:
9204 if( carrier != nullptr ) {
9205 time_duration duration = 15_seconds;
9206 if( carrier->has_trait( trait_TOLERANCE ) ) {
9207 duration = 7_seconds;
9208 } else if( carrier->has_trait( trait_LIGHTWEIGHT ) ) {
9209 duration = 30_seconds;
9210 }
9211 carrier->add_msg_if_player( m_neutral, _( "You take a puff of your %s." ), tname() );
9212 if( has_flag( flag_TOBACCO ) ) {
9213 carrier->add_effect( effect_cig, duration );
9214 } else {
9215 carrier->add_effect( effect_weed_high, duration / 2 );
9216 }
9217 carrier->moves -= 15;
9218
9219 if( ( carrier->has_effect( effect_shakes ) && one_in( 10 ) ) ) {
9220 carrier->add_msg_if_player( m_bad, _( "Your shaking hand causes you to drop your %s." ),
9221 tname() );
9222 here.add_item_or_charges( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), *this );
9223 return true; // removes the item that has just been added to the map
9224 }
9225
9226 if( carrier->has_effect( effect_sleep ) ) {
9227 carrier->add_msg_if_player( m_bad, _( "You fall asleep and drop your %s." ),
9228 tname() );
9229 here.add_item_or_charges( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), *this );
9230 return true; // removes the item that has just been added to the map
9231 }
9232 } else {
9233 // If not carried by someone, but laying on the ground:
9234 if( item_counter % 5 == 0 ) {
9235 // lit cigarette can start fires
9236 if( here.flammable_items_at( pos ) ||
9237 here.has_flag( flag_FLAMMABLE, pos ) ||
9238 here.has_flag( flag_FLAMMABLE_ASH, pos ) ) {
9239 here.add_field( pos, fd_fire, 1 );
9240 }
9241 }
9242 }
9243
9244 // cig dies out
9245 if( item_counter == 0 ) {
9246 if( carrier != nullptr ) {
9247 carrier->add_msg_if_player( m_neutral, _( "You finish your %s." ), tname() );
9248 }
9249 if( typeId() == itype_cig_lit ) {
9251 } else if( typeId() == itype_cigar_lit ) {
9253 } else { // joint
9255 if( carrier != nullptr ) {
9256 carrier->add_effect( effect_weed_high, 1_minutes ); // one last puff
9257 here.add_field( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), fd_weedsmoke, 2 );
9258 weed_msg( *carrier );
9259 }
9260 }
9261 active = false;
9262 }
9263 // Item remains
9264 return false;
9265}
void add_effect(const effect &eff, bool force=false, bool deferred=false)
Definition: creature.cpp:988
bool has_effect(const efftype_id &eff_id, body_part bp=num_bp) const
Check if creature has the matching effect.
Definition: creature.cpp:1187
bool add_field(const tripoint &p, const field_type_id &type_id, int intensity=INT_MAX, const time_duration &age=0_turns, bool hit_player=true)
Add field entry at point, or set intensity if present.
Definition: map.cpp:5506
item & add_item_or_charges(const tripoint &pos, item obj, bool overflow=true)
Adds an item to map tile or stacks charges.
Definition: map.cpp:4332
bool flammable_items_at(const tripoint &p, int threshold=0)
Checks if there are any flammable items on the tile.
Definition: map.cpp:2686
void weed_msg(player &p)
Handles the large variety of weed messages.
Definition: effect.cpp:78
field_type_id fd_fire
Definition: field_type.cpp:345
field_type_id fd_weedsmoke
Definition: field_type.cpp:368
static const efftype_id effect_weed_high("weed_high")
static const trait_id trait_TOLERANCE("TOLERANCE")
static const trait_id trait_LIGHTWEIGHT("LIGHTWEIGHT")
static const std::string flag_FLAMMABLE("FLAMMABLE")
static const efftype_id effect_cig("cig")
static const efftype_id effect_sleep("sleep")
static const std::string flag_FLAMMABLE_ASH("FLAMMABLE_ASH")
static const std::string flag_TOBACCO("TOBACCO")
static const efftype_id effect_shakes("shakes")
Definition: point.h:35

References _, active, Creature::add_effect(), map::add_field(), map::add_item_or_charges(), player::add_msg_if_player(), convert(), effect_cig, effect_shakes, effect_sleep, effect_weed_high, fd_fire, fd_weedsmoke, flag_FLAMMABLE(), flag_FLAMMABLE_ASH(), flag_TOBACCO(), map::flammable_items_at(), get_map(), Creature::has_effect(), has_flag(), map::has_flag(), Character::has_trait(), item_counter, itype_cig_butt, itype_cig_lit, itype_cigar_butt, itype_cigar_lit, itype_joint_roach, m_bad, m_neutral, Creature::moves, one_in(), process_extinguish(), rng(), tname(), trait_LIGHTWEIGHT, trait_TOLERANCE, typeId(), and weed_msg().

Referenced by process_internal().

◆ process_relic()

void item::process_relic ( Character carrier)

Definition at line 9103 of file item.cpp.

9104{
9105 if( !is_relic() ) {
9106 return;
9107 }
9108 std::vector<enchantment> active_enchantments;
9109
9110 for( const enchantment &ench : get_enchantments() ) {
9111 if( ench.is_active( carrier, *this ) ) {
9112 active_enchantments.emplace_back( ench );
9113 }
9114 }
9115
9116 relic_funcs::process_recharge( *this, carrier );
9117}
void process_recharge(item &itm, Character &carrier)
Definition: relic.cpp:449

References get_enchantments(), is_relic(), and relic_funcs::process_recharge().

Referenced by Character::process_turn().

◆ process_rot() [1/2]

bool item::process_rot ( bool  seals,
const tripoint pos,
player carrier,
temperature_flag  flag,
const weather_manager weather_generator 
)

Definition at line 8979 of file item.cpp.

8982{
8983 const time_point now = calendar::turn;
8984
8985 // if player debug menu'd the time backward it breaks stuff, just reset the
8986 // last_temp_check and last_rot_check in this case
8987 if( now - last_rot_check < 0_turns ) {
8988 last_rot_check = now;
8989 return false;
8990 }
8991
8992 // process rot at most once every 100_turns (10 min)
8993 // note we're also gated by item::processing_speed
8994 time_duration smallest_interval = 10_minutes;
8995
8996 units::temperature temp = units::from_fahrenheit( weather.get_temperature( pos ) );
8997 temp = clip_by_temperature_flag( temp, flag );
8998
9001
9002 if( now - time > 1_hours ) {
9003 // This code is for items that were left out of reality bubble for long time
9004
9005 const weather_generator &wgen = weather.get_cur_weather_gen();
9006 const unsigned int seed = g->get_seed();
9007 // It's a modifier, so we need to subtract 0_f
9008 units::temperature local_mod = units::from_fahrenheit( g->new_game
9009 ? 0
9010 : get_map().get_temperature( pos ) ) - 0_f;
9011
9012 // Process the past of this item since the last time it was processed
9013 while( now - time > 1_hours ) {
9014 // Get the environment temperature
9015 time_duration time_delta = std::min( 1_hours, now - 1_hours - time );
9016 time += time_delta;
9017
9018 //Use weather if above ground, use map temp if below
9019 units::temperature env_temperature_raw;
9020 if( pos.z >= 0 ) {
9021 tripoint_abs_ms location = tripoint_abs_ms( get_map().getabs( pos ) );
9022 units::temperature weather_temperature = wgen.get_weather_temperature( location, time,
9024 env_temperature_raw = weather_temperature + local_mod;
9025 } else {
9026 env_temperature_raw = units::from_fahrenheit( AVERAGE_ANNUAL_TEMPERATURE ) + local_mod;
9027 }
9028
9029 units::temperature env_temperature_clipped = clip_by_temperature_flag( env_temperature_raw, flag );
9030
9031 // Lookup table is in F
9032 int final_temperature_in_fahrenheit = static_cast<int>( std::round( units::to_fahrenheit<float>
9033 ( env_temperature_clipped ) ) );
9034
9035 // Calculate item rot
9036 rot += calc_rot( time, final_temperature_in_fahrenheit );
9038
9039 if( has_rotten_away() && carrier == nullptr && !seals ) {
9040 // No need to track item that will be gone
9041 return true;
9042 }
9043 }
9044 }
9045
9046 // Remaining <1 h from above
9047 // and items that are held near the player
9048 if( now - time > smallest_interval ) {
9049 int final_temperature_in_fahrenheit = static_cast<int>( std::round( units::to_fahrenheit<float>
9050 ( temp ) ) );
9051
9052 rot += calc_rot( now, final_temperature_in_fahrenheit );
9053 last_rot_check = now;
9054
9055 return has_rotten_away() && carrier == nullptr && !seals;
9056 }
9057
9058 return false;
9059}
time_duration calc_rot(time_point time, int temp) const
Returns rot of the item since last rot calculation.
Definition: item.cpp:5651
bool has_rotten_away() const
Whether the item has enough rot that it should get removed.
Definition: item.cpp:8795
A point in the game time.
Definition: calendar.h:431
units::temperature get_weather_temperature(const tripoint_abs_ms &, const time_point &, const calendar_config &calendar_config, unsigned) const
coords::coord_point< tripoint, coords::origin::abs, coords::ms > tripoint_abs_ms
Definition: coordinates.h:486
static constexpr int AVERAGE_ANNUAL_TEMPERATURE
Average annual temperature in F used for climate, weather and temperature calculation.
static units::temperature clip_by_temperature_flag(units::temperature temperature, temperature_flag flag)
Definition: item.cpp:8956
calendar_config config
int seed(player *, item *, bool, const tripoint &)
Definition: iuse.cpp:6011
constexpr quantity< value_type, temperature_in_millidegree_celsius_tag > from_fahrenheit(const value_type v)
int z
Definition: point.h:138

References AVERAGE_ANNUAL_TEMPERATURE, calc_rot(), clip_by_temperature_flag(), calendar::config, units::from_fahrenheit(), g, get_map(), weather_generator::get_weather_temperature(), has_rotten_away(), last_rot_check, iuse::seed(), time, calendar::turn, and tripoint::z.

◆ process_rot() [2/2]

bool item::process_rot ( const tripoint pos)

Update temperature for things like food Update rot for things that perish All items that rot also have temperature.

Parameters
sealsWether the item is in sealed container
posThe current position
carrierThe current carrier
flagto specify special temperature situations
weather_generatorweather manager, mostly for testing
Returns
true if the item is fully rotten and is ready to be removed

Definition at line 8951 of file item.cpp.

8952{
8953 return process_rot( false, pos, nullptr, temperature_flag::TEMP_NORMAL, get_weather() );
8954}

References get_weather(), process_rot(), and TEMP_NORMAL.

Referenced by actualize_rot(), process_internal(), and process_rot().

◆ process_tool()

bool item::process_tool ( player carrier,
const tripoint pos 
)
protected

Definition at line 9466 of file item.cpp.

9467{
9468 avatar &you = get_avatar();
9469 // items with iuse set_transformed which are restricted turn off if not attached to their dependency.
9470 if( type->can_use( "set_transformed" ) ) {
9471 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
9472 ( this->get_use( "set_transformed" )->get_actor_ptr() );
9473 if( actor == nullptr ) {
9474 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
9475 return false;
9476 }
9477 if( actor->restricted ) {
9478 if( !carrier ) {
9479 actor->bypass( carrier != nullptr ? *carrier : you, *this, false, pos );
9480 return false;
9481 } else {
9482 bool active = false;
9483 std::string transform_flag = actor->dependencies;
9484 for( const auto &elem : carrier->worn ) {
9485 if( elem.active && elem.has_flag( transform_flag ) ) {
9486 active = true;
9487 break;
9488 }
9489 }
9490 if( !active ) {
9491 actor->bypass( carrier != nullptr ? *carrier : you, *this, false, pos );
9492 return false;
9493 }
9494 }
9495 }
9496 }
9497
9498 int energy = 0;
9499 if( type->tool->turns_per_charge > 0 &&
9500 to_turn<int>( calendar::turn ) % type->tool->turns_per_charge == 0 ) {
9501 energy = std::max( ammo_required(), 1 );
9502
9503 } else if( type->tool->power_draw > 0 ) {
9504 // power_draw in mW / 1000000 to give kJ (battery unit) per second
9505 energy = type->tool->power_draw / 1000000;
9506 // energy_bat remainder results in chance at additional charge/discharge
9507 energy += x_in_y( type->tool->power_draw % 1000000, 1000000 ) ? 1 : 0;
9508 }
9509 energy -= ammo_consume( energy, pos );
9510
9511 // for power armor pieces, try to use power armor interface first.
9512 if( carrier && is_power_armor() && character_funcs::can_interface_armor( *carrier ) ) {
9513 if( carrier->use_charges_if_avail( itype_bio_armor, energy ) ) {
9514 energy = 0;
9515 }
9516 }
9517
9518 // for items in player possession if insufficient charges within tool try UPS
9519 if( carrier && ( has_flag( flag_USE_UPS ) ) ) {
9520 if( carrier->use_charges_if_avail( itype_UPS, energy ) ) {
9521 energy = 0;
9522 }
9523 }
9524
9525 // if insufficient available charges shutdown the tool
9526 if( energy > 0 ) {
9527 if( carrier ) {
9528 if( is_power_armor() ) {
9529 if( has_flag( flag_USE_UPS ) ) {
9530 carrier->add_msg_if_player( m_info, _( "You need a UPS or Bionic Power Interface to run the %s!" ),
9531 tname() );
9532 } else {
9533 carrier->add_msg_if_player( m_info, _( "You need a Bionic Power Interface to run the %s!" ),
9534 tname() );
9535 }
9536 } else if( has_flag( flag_USE_UPS ) ) {
9537 carrier->add_msg_if_player( m_info, _( "You need a UPS to run the %s!" ), tname() );
9538 }
9539 }
9540 if( carrier && type->can_use( "set_transform" ) ) {
9541 const set_transform_iuse *actor = dynamic_cast<const set_transform_iuse *>
9542 ( this->get_use( "set_transform" )->get_actor_ptr() );
9543 if( actor == nullptr ) {
9544 debugmsg( "iuse_actor type descriptor and actual type mismatch." );
9545 return false;
9546 }
9547 std::string transformed_flag = actor->flag;
9548 for( auto &elem : carrier->worn ) {
9549 if( elem.active && elem.has_flag( transformed_flag ) ) {
9550 if( !elem.type->can_use( "set_transformed" ) ) {
9551 debugmsg( "Expected set_transformed function" );
9552 return false;
9553 }
9554 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
9555 ( elem.get_use( "set_transformed" )->get_actor_ptr() );
9556 if( actor == nullptr ) {
9557 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
9558 return false;
9559 }
9560 actor->bypass( *carrier, elem, false, pos );
9561 }
9562 }
9563 }
9564
9565 // invoking the object can convert the item to another type
9566 const bool had_revert_to = type->tool->revert_to.has_value();
9567 type->invoke( carrier != nullptr ? *carrier : you, *this, pos );
9568 if( had_revert_to ) {
9569 deactivate( carrier );
9570 return false;
9571 } else {
9572 return true;
9573 }
9574 }
9575
9576 type->tick( carrier != nullptr ? *carrier : you, *this, pos );
9577 return false;
9578}
bool use_charges_if_avail(const itype_id &it, int quantity)
Definition: character.cpp:9634
item & deactivate(const Character *ch=nullptr, bool alert=true)
Filter converting this instance to the inactive type If the item is either inactive or cannot be deac...
Definition: item.cpp:540
This is a iuse_transform that changes a set of items with a specific flag.
Definition: iuse_actor.h:318
std::string flag
Flag string so we know what the heck we're transforming.
Definition: iuse_actor.h:328
static const itype_id itype_UPS("UPS")
static const itype_id itype_bio_armor("bio_armor")
bool can_interface_armor(const Character &who)
Check whether character has an active bionic capable of interfacing with power armor.
void tick(player &p, item &it, const tripoint &pos) const
Definition: itype.cpp:172

References _, active, player::add_msg_if_player(), ammo_consume(), ammo_required(), set_transformed_iuse::bypass(), character_funcs::can_interface_armor(), itype::can_use(), deactivate(), debugmsg, set_transformed_iuse::dependencies, energy, set_transform_iuse::flag, flag_USE_UPS(), use_function::get_actor_ptr(), get_avatar(), get_use(), has_flag(), itype::invoke(), is_power_armor(), itype_bio_armor, itype_UPS, m_info, set_transformed_iuse::restricted, itype::tick(), tname(), itype::tool, calendar::turn, type, Character::use_charges_if_avail(), Character::worn, and x_in_y().

Referenced by process_internal().

◆ process_UPS()

bool item::process_UPS ( player carrier,
const tripoint pos 
)
protected

Definition at line 9435 of file item.cpp.

9436{
9437 if( carrier == nullptr ) {
9438 erase_var( "cable" );
9439 active = false;
9440 return false;
9441 }
9442 bool has_connected_cable = carrier->has_item_with( []( const item & it ) {
9443 return it.active && it.has_flag( flag_CABLE_SPOOL ) && ( it.get_var( "state" ) == "UPS_link" ||
9444 it.get_var( "state" ) == "UPS" );
9445 } );
9446 if( !has_connected_cable ) {
9447 erase_var( "cable" );
9448 active = false;
9449 }
9450 return false;
9451}

References active, erase_var(), flag_CABLE_SPOOL(), get_var(), has_flag(), and visitable< T >::has_item_with().

Referenced by process_internal().

◆ process_wet()

bool item::process_wet ( player carrier,
const tripoint pos 
)
protected

Definition at line 9453 of file item.cpp.

9454{
9455 if( item_counter == 0 ) {
9456 if( is_tool() && type->tool->revert_to ) {
9457 convert( *type->tool->revert_to );
9458 }
9459 unset_flag( "WET" );
9460 active = false;
9461 }
9462 // Always return true so our caller will bail out instead of processing us as a tool.
9463 return true;
9464}

References active, convert(), is_tool(), item_counter, itype::tool, type, and unset_flag().

Referenced by process_internal().

◆ processing_speed()

int item::processing_speed ( ) const

The rate at which an item should be processed, in number of turns between updates.

Definition at line 8942 of file item.cpp.

8943{
8944 if( is_corpse() || is_food() || is_food_container() ) {
8945 return to_turns<int>( 10_minutes );
8946 }
8947 // Unless otherwise indicated, update every turn.
8948 return 1;
8949}

References is_corpse(), is_food(), and is_food_container().

Referenced by active_item_cache::add(), and active_item_cache::remove().

◆ put_in()

◆ qualities_info()

void item::qualities_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3228 of file item.cpp.

3230{
3231 auto name_quality = [&info]( const std::pair<quality_id, int> &q ) {
3232 std::string str;
3233 if( q.first == qual_JACK || q.first == qual_LIFT ) {
3234 str = string_format( _( "Has level <info>%1$d %2$s</info> quality and "
3235 "is rated at <info>%3$d</info> %4$s" ),
3236 q.second, q.first.obj().name,
3237 static_cast<int>( convert_weight( q.second * TOOL_LIFT_FACTOR ) ),
3238 weight_units() );
3239 } else {
3240 str = string_format( _( "Has level <info>%1$d %2$s</info> quality." ),
3241 q.second, q.first.obj().name );
3242 }
3243 info.emplace_back( "QUALITIES", "", str );
3244 };
3245
3246 if( parts->test( iteminfo_parts::QUALITIES ) ) {
3248 for( const std::pair<const quality_id, int> q : sorted_lex( type->qualities ) ) {
3249 name_quality( q );
3250 }
3251 }
3252
3254 contents.has_any_with( []( const item & e ) {
3255 return !e.type->qualities.empty();
3256 } ) ) {
3257
3258 info.emplace_back( "QUALITIES", "", _( "Contains items with qualities:" ) );
3259 std::map<quality_id, int, quality_id::LexCmp> most_quality;
3260 for( const item *e : contents.all_items_top() ) {
3261 for( const std::pair<const quality_id, int> &q : e->type->qualities ) {
3262 auto emplace_result = most_quality.emplace( q );
3263 if( !emplace_result.second &&
3264 most_quality.at( emplace_result.first->first ) < q.second ) {
3265 most_quality[ q.first ] = q.second;
3266 }
3267 }
3268 }
3269 for( const std::pair<const quality_id, int> &q : most_quality ) {
3270 name_quality( q );
3271 }
3272 }
3273}
bool has_any_with(const std::function< bool(const item &)> &filter) const
#define TOOL_LIFT_FACTOR
static const quality_id qual_JACK("JACK")
static const quality_id qual_LIFT("LIFT")

References _, item_contents::all_items_top(), contents, convert_weight(), item_contents::has_any_with(), info(), insert_separation_line(), qual_JACK, qual_LIFT, QUALITIES, itype::qualities, QUALITIES_CONTAINED, sorted_lex(), string_format(), iteminfo_query::test(), TOOL_LIFT_FACTOR, type, and weight_units().

Referenced by info().

◆ quality_of()

const std::map< quality_id, int > & item::quality_of ( ) const

The ids of all the qualities this contains.

Definition at line 6421 of file item.cpp.

6422{
6423 return type->qualities;
6424}

References itype::qualities, and type.

◆ reach_range()

int item::reach_range ( const Character guy) const

Max range of melee attack this weapon can be used for.

Accounts for character's abilities and installed gun mods. Guaranteed to be at least 1

Definition at line 5265 of file item.cpp.

5266{
5267 int res = 1;
5268
5269 if( has_flag( flag_REACH_ATTACK ) ) {
5270 res = has_flag( flag_REACH3 ) ? 3 : 2;
5271 }
5272
5273 // for guns consider any attached gunmods
5274 if( is_gun() && !is_gunmod() ) {
5275 for( const std::pair<const gun_mode_id, gun_mode> &m : gun_all_modes() ) {
5276 if( guy.is_npc() && m.second.flags.count( "NPC_AVOID" ) ) {
5277 continue;
5278 }
5279 if( m.second.melee() ) {
5280 res = std::max( res, m.second.qty );
5281 }
5282 }
5283 }
5284
5285 return std::max( 1, res );
5286}
virtual bool is_npc() const
Definition: creature.h:98

References flag_REACH3(), flag_REACH_ATTACK(), gun_all_modes(), has_flag(), is_gun(), is_gunmod(), and Creature::is_npc().

Referenced by avatar_action::autoattack(), fire(), npc::invalidate_range_cache(), Character::melee_attack(), npc_ai::melee_value(), npc::method_of_attack(), and target_handler::mode_reach().

◆ ready_to_revive()

bool item::ready_to_revive ( const tripoint pos) const

Whether this corpse should revive now.

Note that this function includes some randomness, the return value can differ on successive calls.

Parameters
posThe location of the item (see REVIVE_SPECIAL flag).

Definition at line 5965 of file item.cpp.

5966{
5967 if( !can_revive() ) {
5968 return false;
5969 }
5970 if( get_map().veh_at( pos ) ) {
5971 return false;
5972 }
5973 if( !calendar::once_every( 1_seconds ) ) {
5974 return false;
5975 }
5976 int age_in_hours = to_hours<int>( age() );
5977 age_in_hours -= static_cast<int>( static_cast<float>( burnt ) / ( volume() / 250_ml ) );
5978 if( damage_level( 4 ) > 0 ) {
5979 age_in_hours /= ( damage_level( 4 ) + 1 );
5980 }
5981 int rez_factor = 48 - age_in_hours;
5982 if( age_in_hours > 6 && ( rez_factor <= 0 || one_in( rez_factor ) ) ) {
5983 // If we're a special revival zombie, wait to get up until the player is nearby.
5984 const bool isReviveSpecial = has_flag( flag_REVIVE_SPECIAL );
5985 if( isReviveSpecial ) {
5986 const int distance = rl_dist( pos, get_player_character().pos() );
5987 if( distance > 3 ) {
5988 return false;
5989 }
5990 if( !one_in( distance + 1 ) ) {
5991 return false;
5992 }
5993 }
5994
5995 return true;
5996 }
5997 return false;
5998}
static const std::string flag_REVIVE_SPECIAL("REVIVE_SPECIAL")
bool once_every(const time_duration &event_frequency)
Predicate to handle rate-limiting.
Definition: calendar.cpp:490

References age(), burnt, can_revive(), damage_level(), flag_REVIVE_SPECIAL(), get_map(), get_player_character(), has_flag(), calendar::once_every(), one_in(), rl_dist(), and volume().

Referenced by process_corpse().

◆ reinforceable()

bool item::reinforceable ( ) const

Whether the item can be repaired beyond normal health.

Definition at line 6499 of file item.cpp.

6500{
6501 if( is_null() || has_flag( flag_NO_REPAIR ) ) {
6502 return false;
6503 }
6504
6505 // If a material is reinforceable, so are we
6506 const std::vector<const material_type *> &mats = made_of_types();
6507 return std::any_of( mats.begin(), mats.end(), []( const material_type * mt ) {
6508 return mt->reinforces();
6509 } );
6510}
static const std::string flag_NO_REPAIR("NO_REPAIR")

References flag_NO_REPAIR(), has_flag(), is_null(), and made_of_types().

Referenced by repair_item_actor::can_repair_target(), repair_item_actor::repair(), and repair_info().

◆ release_monster()

bool item::release_monster ( const tripoint target,
int  radius = 0 
)

Definition at line 9236 of file iuse.cpp.

9237{
9238 shared_ptr_fast<monster> new_monster = make_shared_fast<monster>();
9239 try {
9240 ::deserialize( *new_monster, get_var( "contained_json", "" ) );
9241 } catch( const std::exception &e ) {
9242 debugmsg( _( "Error restoring monster: %s" ), e.what() );
9243 return false;
9244 }
9245 if( !g->place_critter_around( new_monster, target, radius ) ) {
9246 return false;
9247 }
9248 erase_var( "contained_name" );
9249 erase_var( "contained_json" );
9250 erase_var( "name" );
9251 erase_var( "weight" );
9252 return true;
9253}
void deserialize(JsonIn &jsin)
std::shared_ptr< T > shared_ptr_fast
Definition: memory_fast.h:16

References _, debugmsg, deserialize(), erase_var(), g, and get_var().

Referenced by iuse::capture_monster_act(), and DefaultRemovePartHandler::spawn_animal_from_part().

◆ reload()

bool item::reload ( player u,
item_location  loc,
int  qty 
)

Reload item using ammo from location returning true if successful.

Parameters
uPlayer doing the reloading
locLocation of ammo to be reloaded
qtycaps reloading to this (or fewer) units

Definition at line 8111 of file item.cpp.

8112{
8113 if( qty <= 0 ) {
8114 debugmsg( "Tried to reload zero or less charges" );
8115 return false;
8116 }
8117 item *ammo = loc.get_item();
8118 if( ammo == nullptr || ammo->is_null() ) {
8119 debugmsg( "Tried to reload using non-existent ammo" );
8120 return false;
8121 }
8122
8123 item *container = nullptr;
8124 if( ammo->is_ammo_container() || ammo->is_container() ) {
8125 container = ammo;
8126 ammo = &ammo->contents.front();
8127 }
8128
8129 if( !is_reloadable_with( ammo->typeId() ) ) {
8130 return false;
8131 }
8132
8133 // limit quantity of ammo loaded to remaining capacity
8134 int limit = is_watertight_container()
8137
8138 if( ammo->ammo_type() == ammo_plutonium ) {
8139 limit = limit / PLUTONIUM_CHARGES + ( limit % PLUTONIUM_CHARGES != 0 );
8140 }
8141
8142 qty = std::min( qty, limit );
8143
8144 casings_handle( [&u]( item & e ) {
8145 return u.i_add_or_drop( e );
8146 } );
8147
8148 if( is_magazine() ) {
8149 qty = std::min( qty, ammo->charges );
8150
8151 if( is_ammo_belt() && type->magazine->linkage ) {
8152 if( !u.use_charges_if_avail( *type->magazine->linkage, qty ) ) {
8153 debugmsg( "insufficient linkages available when reloading ammo belt" );
8154 }
8155 }
8156
8157 item to_reload = *ammo;
8158 to_reload.charges = qty;
8159 ammo->charges -= qty;
8160 bool merged = false;
8161 for( item *it : contents.all_items_top() ) {
8162 if( it->merge_charges( to_reload ) ) {
8163 merged = true;
8164 break;
8165 }
8166 }
8167 if( !merged ) {
8168 put_in( to_reload );
8169 }
8170 } else if( is_watertight_container() ) {
8171 if( !ammo->made_of( LIQUID ) ) {
8172 debugmsg( "Tried to reload liquid container with non-liquid." );
8173 return false;
8174 }
8175 if( container ) {
8176 container->on_contents_changed();
8177 }
8178 fill_with( *ammo, qty );
8179 } else if( !magazine_integral() ) {
8180 // if we already have a magazine loaded prompt to eject it
8181 if( magazine_current() ) {
8182 //~ %1$s: magazine name, %2$s: weapon name
8183 std::string prompt = string_format( pgettext( "magazine", "Eject %1$s from %2$s?" ),
8184 magazine_current()->tname(), tname() );
8185
8186 // eject magazine to player inventory and try to dispose of it from there
8187 item &mag = u.i_add( *magazine_current() );
8188 if( !u.dispose_item( item_location( u, &mag ), prompt ) ) {
8189 u.remove_item( mag ); // user canceled so delete the clone
8190 return false;
8191 }
8193 }
8194
8195 put_in( *ammo );
8196 loc.remove_item();
8197 return true;
8198
8199 } else {
8200 if( ammo->has_flag( flag_SPEEDLOADER ) ) {
8201 curammo = ammo->contents.front().type;
8202 qty = std::min( qty, ammo->ammo_remaining() );
8203 ammo->ammo_consume( qty, tripoint_zero );
8204 charges += qty;
8205 } else if( ammo->ammo_type() == ammo_plutonium ) {
8206 curammo = ammo->type;
8207 ammo->charges -= qty;
8208
8209 // any excess is wasted rather than overfilling the item
8210 charges += qty * PLUTONIUM_CHARGES;
8211 charges = std::min( charges, ammo_capacity() );
8212 } else {
8213 curammo = ammo->type;
8214 qty = std::min( qty, ammo->charges );
8215 ammo->charges -= qty;
8216 charges += qty;
8217 }
8218 }
8219
8220 if( ammo->charges == 0 && !ammo->has_flag( flag_SPEEDLOADER ) ) {
8221 if( container != nullptr ) {
8222 container->remove_item( container->contents.front() );
8223 u.inv.restack( u ); // emptied containers do not stack with non-empty ones
8224 } else {
8225 loc.remove_item();
8226 }
8227 }
8228 return true;
8229}
item & i_add(item it, bool should_stack=true)
Definition: character.cpp:2262
bool i_add_or_drop(item &it, int qty=1)
Sets invlet and adds to inventory if possible, drops otherwise, returns true if either succeeded.
Definition: character.cpp:2401
virtual bool dispose_item(item_location &&obj, const std::string &prompt=std::string())
Drop, wear, stash or otherwise try to dispose of an item consuming appropriate moves.
Definition: character.cpp:7251
void restack(player &p)
Definition: inventory.cpp:399
item * get_item()
Gets the selected item or nullptr.
void remove_item()
Removes the selected item from the game.
void fill_with(item &liquid, int amount=INFINITE_CHARGES)
Fill item with liquid up to its capacity.
Definition: item.cpp:8568
bool is_ammo_belt() const
Definition: item.cpp:6567
static constexpr int PLUTONIUM_CHARGES
static const ammotype ammo_plutonium("plutonium")
static const std::string flag_SPEEDLOADER("SPEEDLOADER")
@ prompt
Definition: pickup.h:30
static constexpr tripoint tripoint_zero
Definition: point.h:259

References item_contents::all_items_top(), ammo_capacity(), ammo_consume(), ammo_plutonium, ammo_remaining(), ammo_type(), casings_handle(), charges, contents, curammo, debugmsg, Character::dispose_item(), fill_with(), flag_SPEEDLOADER(), item_contents::front(), item_location::get_item(), get_remaining_capacity_for_liquid(), has_flag(), Character::i_add(), Character::i_add_or_drop(), Character::inv, is_ammo_belt(), is_ammo_container(), is_container(), is_magazine(), is_null(), is_reloadable_with(), is_watertight_container(), LIQUID, made_of(), itype::magazine, magazine_current(), magazine_integral(), on_contents_changed(), pgettext(), PLUTONIUM_CHARGES, pickup::prompt, put_in(), item_location::remove_item(), visitable< item >::remove_item(), visitable< T >::remove_item(), inventory::restack(), string_format(), tname(), tripoint_zero, type, typeId(), and Character::use_charges_if_avail().

Referenced by veh_interact::complete_vehicle(), npc::do_reload(), ranged::fire_gun(), and activity_handlers::reload_finish().

◆ remove_old_owner()

void item::remove_old_owner ( ) const
inline

Definition at line 2026 of file item.h.

2026 {
2028 }

References string_id< faction >::NULL_ID().

Referenced by talk_function::drop_stolen_item(), and validate_ownership().

◆ remove_owner()

void item::remove_owner ( ) const
inline

Definition at line 2033 of file item.h.

2033 {
2035 }

References string_id< faction >::NULL_ID().

Referenced by validate_ownership().

◆ repair_info()

void item::repair_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3153 of file item.cpp.

3155{
3157 return;
3158 }
3160 const std::vector<itype_id> &rep = sorted_lex( repaired_with() );
3161 if( !rep.empty() ) {
3162 info.emplace_back( "DESCRIPTION", string_format( _( "<bold>Repair</bold> using %s." ),
3163 enumerate_as_string( rep.begin(), rep.end(), []( const itype_id & e ) {
3164 return nname( e );
3166 if( reinforceable() ) {
3167 info.emplace_back( "DESCRIPTION", _( "* This item can be <good>reinforced</good>." ) );
3168 }
3169 } else {
3170 info.emplace_back( "DESCRIPTION", _( "* This item is <bad>not repairable</bad>." ) );
3171 }
3172}
bool reinforceable() const
Whether the item can be repaired beyond normal health.
Definition: item.cpp:6499
const std::set< itype_id > & repaired_with() const
If possible to repair this item what tools could potentially be used for this purpose?
Definition: item.cpp:6357

References _, DESCRIPTION_REPAIREDWITH, enumerate_as_string(), info(), insert_separation_line(), or_, reinforceable(), repaired_with(), sorted_lex(), string_format(), and iteminfo_query::test().

Referenced by info().

◆ repaired_with()

const std::set< itype_id > & item::repaired_with ( ) const

If possible to repair this item what tools could potentially be used for this purpose?

Definition at line 6357 of file item.cpp.

6358{
6359 static std::set<itype_id> no_repair;
6360 return has_flag( flag_NO_REPAIR ) ? no_repair : type->repair;
6361}
std::set< itype_id > repair
Damage scale compared to the old float damage value.
Definition: itype.h:1011

References flag_NO_REPAIR(), has_flag(), itype::repair, and type.

Referenced by repair_info().

◆ reset_cable()

void item::reset_cable ( player p)

Helper to bring a cable back to its initial state.

Definition at line 9418 of file item.cpp.

9419{
9420 int max_charges = type->maximum_charges();
9421
9422 set_var( "state", "attach_first" );
9423 erase_var( "source_x" );
9424 erase_var( "source_y" );
9425 erase_var( "source_z" );
9426 active = false;
9427 charges = max_charges;
9428
9429 if( p != nullptr ) {
9430 p->add_msg_if_player( m_info, _( "You reel in the cable." ) );
9431 p->moves -= charges * 10;
9432 }
9433}

References _, active, player::add_msg_if_player(), charges, erase_var(), m_info, itype::maximum_charges(), Creature::moves, set_var(), and type.

Referenced by process_cable().

◆ rotten()

◆ serialize()

void item::serialize ( JsonOut json) const

Definition at line 2390 of file savegame_json.cpp.

2391{
2392 io::JsonObjectOutputArchive archive( json );
2393 const_cast<item *>( this )->io( archive );
2394 if( !contents.empty() ) {
2395 json.member( "contents", contents );
2396 }
2397}
void member(const std::string &name)
Definition: json.cpp:2235
Output archive matching the input archive JsonObjectInputArchive.
Definition: cata_io.h:351

References contents, item_contents::empty(), io(), and JsonOut::member().

Referenced by contain_monster().

◆ set_age()

void item::set_age ( const time_duration age)

Definition at line 10010 of file item.cpp.

10011{
10013}
void set_birthday(const time_point &bday)
Definition: item.cpp:10031

References age(), set_birthday(), and calendar::turn.

Referenced by burn(), iuse::firecracker_pack(), iuse::fish_trap(), iexamine::fvat_empty(), vehicle::operate_planter(), and map::process_fields_in_submap().

◆ set_birthday()

void item::set_birthday ( const time_point bday)

Definition at line 10031 of file item.cpp.

10032{
10033 this->bday = std::max( calendar::turn_zero, bday );
10034}

References bday, and calendar::turn_zero.

Referenced by editmap::edit_itm(), retroactively_fill_from_funnel(), set_age(), and debug_menu::wishitem().

◆ set_cached_tool_selections()

void item::set_cached_tool_selections ( const std::vector< comp_selection< tool_comp > > &  selections)

Definition at line 10112 of file item.cpp.

10113{
10114 assert( craft_data_ );
10115 craft_data_->cached_tool_selections = selections;
10116}

References craft_data_.

Referenced by craft_command::create_in_progress_craft().

◆ set_countdown()

void item::set_countdown ( int  num_turns)

Sets time until activation for an item that will self-activate in the future.

Definition at line 8603 of file item.cpp.

8604{
8605 if( num_turns < 0 ) {
8606 debugmsg( "Tried to set a negative countdown value %d.", num_turns );
8607 return;
8608 }
8609 if( !ammo_types().empty() ) {
8610 debugmsg( "Tried to set countdown on an item with ammo." );
8611 return;
8612 }
8613 charges = num_turns;
8614}

References ammo_types(), charges, and debugmsg.

Referenced by iuse_transform::use().

◆ set_damage()

item & item::set_damage ( int  qty)

Filter setting damage constrained by min_damage and max_damage.

Note
this method does not invoke the on_damage callback
Returns
same instance to allow method chaining

Definition at line 714 of file item.cpp.

715{
716 on_damage( qty - damage_, DT_TRUE );
717 damage_ = std::max( std::min( qty, max_damage() ), min_damage() );
718 return *this;
719}

References damage_, DT_TRUE, max_damage(), min_damage(), and on_damage().

Referenced by mdeath::broken(), editmap::edit_itm(), iuse::gun_repair(), Item_modifier::modify(), vehicle_part::properties_to_item(), repair_item_actor::repair(), game::save_cyborg(), vehicle::set_hp(), and map::spawn_an_item().

◆ set_favorite()

void item::set_favorite ( bool  favorite)

Definition at line 10084 of file item.cpp.

10085{
10086 is_favorite = favorite;
10087}

References is_favorite.

Referenced by advanced_inventory::display(), and inventory_column::set_stack_favorite().

◆ set_flag()

item & item::set_flag ( const std::string &  flag)

Idempotent filter setting an item specific flag.

Definition at line 5332 of file item.cpp.

5333{
5334 item_tags.insert( flag );
5335 return *this;
5336}
iterator insert(iterator, const value_type &value)
Definition: flat_set.h:151

References cata::flat_set< T, Compare, Data >::insert(), and item_tags.

Referenced by map::add_corpse(), ammo_set(), are_requirements_nearby(), iexamine::autodoc(), explosion_handler::ExplosionProcess::blast_tile(), butcher_cbm_item(), activity_handlers::butcher_finish(), butchery_quarter(), iuse::camera(), crafting::complete_disassemble(), recipe::create_byproducts(), Single_item_creator::create_single(), cycle_action(), game::dump_stats(), heal_actor::finish_using(), basecamp::form_crafting_inventory(), inventory::form_from_map(), activity_handlers::repair_activity_hack::anonymous_namespace{activity_handlers.cpp}::get_fake_tool(), iuse_transform::info(), inherit_flags(), init_memory_card_with_random_stuff(), item(), Item_factory::migrate_item(), Item_modifier::modify(), explosion_handler::ExplosionProcess::move_entity(), iexamine::nanofab(), on_damage(), on_drop(), vehicle_part::properties_to_item(), iuse::radio_mod(), activity_handlers::reload_finish(), repair_item_actor::repair(), mattack::riotbot(), set_flag_recursive(), spell_effect::spawn_ethereal_item(), map::spawn_item(), starting_clothes(), starting_inv(), iuse::towel_common(), avatar_funcs::unload_item(), sew_advanced_actor::use(), unpack_actor::use(), iexamine::use_furn_fake_item(), and vehicle_part::vehicle_part().

◆ set_flag_recursive()

item & item::set_flag_recursive ( const std::string &  flag)

Idempotent filter recursively setting an item specific flag on this item and its components.

Definition at line 5344 of file item.cpp.

5345{
5346 set_flag( flag );
5347 for( item &comp : components ) {
5348 comp.set_flag_recursive( flag );
5349 }
5350 return *this;
5351}

References components, and set_flag().

◆ set_mtype()

void item::set_mtype ( const mtype m)

Sets the monster type associated with this item (corpse).

You must not pass a null pointer. TODO: change this to take a reference instead.

Definition at line 6652 of file item.cpp.

6653{
6654 // This is potentially dangerous, e.g. for corpse items, which *must* have a valid mtype pointer.
6655 if( m == nullptr ) {
6656 debugmsg( "setting item::corpse of %s to NULL", tname() );
6657 return;
6658 }
6659 corpse = m;
6660}

References corpse, debugmsg, and tname().

Referenced by iuse::blood_draw().

◆ set_next_failure_point()

void item::set_next_failure_point ( const player crafter)

Calculates and sets the next failure point for an in progress craft.

Causes a debugmsg if called on non-craft.

Parameters
crafterthe crafting player

Definition at line 904 of file crafting.cpp.

905{
906 if( !is_craft() ) {
907 debugmsg( "set_next_failure_point() called on non-craft '%s.' Aborting.", tname() );
908 return;
909 }
910
911 const int percent_left = 10000000 - item_counter;
912 const int failure_point_delta = crafter.crafting_success_roll( get_making() ) * percent_left;
913
914 craft_data_->next_failure_point = item_counter + failure_point_delta;
915}

References craft_data_, player::crafting_success_roll(), debugmsg, get_making(), is_craft(), item_counter, and tname().

Referenced by craft_command::create_in_progress_craft(), and handle_craft_failure().

◆ set_old_owner()

void item::set_old_owner ( const faction_id temp_owner)
inline

Definition at line 2023 of file item.h.

2023 {
2024 old_owner = temp_owner;
2025 }

Referenced by handle_pickup_ownership().

◆ set_owner() [1/2]

void item::set_owner ( const Character c)

Definition at line 1270 of file item.cpp.

1271{
1272 if( !c.get_faction() ) {
1273 debugmsg( "item::set_owner() Character %s has no valid faction", c.disp_name() );
1274 return;
1275 }
1276 owner = c.get_faction()->id;
1277}

References c, debugmsg, and owner.

◆ set_owner() [2/2]

◆ set_relative_rot()

void item::set_relative_rot ( double  val)

Set current item rot relative to shelf life (no-op if item does not spoil)

Definition at line 5539 of file item.cpp.

5540{
5541 if( goes_bad() ) {
5542 rot = get_shelf_life() * val;
5543 // calc_rot uses last_rot_check (when it's not turn_zero) instead of bday.
5544 // this makes sure the rotting starts from now, not from bday.
5545 // if this item is the result of smoking or milling don't do this, we want to start from bday.
5548 }
5549 }
5550}
static const std::string flag_PROCESSING_RESULT("PROCESSING_RESULT")

References flag_PROCESSING_RESULT(), get_shelf_life(), goes_bad(), has_flag(), last_rot_check, and calendar::turn.

Referenced by complete_craft(), fill_with(), item(), and iexamine::keg().

◆ set_rot()

void item::set_rot ( time_duration  val)

Definition at line 5552 of file item.cpp.

5553{
5554 rot = val;
5555}

◆ set_side()

bool item::set_side ( side  s)

Change the side on which the item is worn.

Returns false if the item is not sided

Definition at line 815 of file item.cpp.

816{
817 if( !is_sided() ) {
818 return false;
819 }
820
821 if( s == side::BOTH ) {
822 erase_var( "lateral" );
823 } else {
824 set_var( "lateral", static_cast<int>( s ) );
825 }
826
827 return true;
828}

References BOTH, erase_var(), is_sided(), and set_var().

Referenced by on_takeoff(), on_wear(), and swap_side().

◆ set_snippet()

void item::set_snippet ( const snippet_id id)

Set the snippet text (description) of this specific item, using the snippet library.

See also
snippet_library.

Definition at line 8679 of file item.cpp.

8680{
8681 if( is_null() ) {
8682 return;
8683 }
8684 if( !id.is_valid() ) {
8685 debugmsg( "there's no snippet with id %s", id.str() );
8686 return;
8687 }
8688 snip_id = id;
8689}

References debugmsg, base_camps::id, is_null(), and snip_id.

Referenced by profession::items().

◆ set_tools_to_continue()

void item::set_tools_to_continue ( bool  value)

Definition at line 10100 of file item.cpp.

10101{
10102 assert( craft_data_ );
10103 craft_data_->tools_to_continue = value;
10104}

References craft_data_.

Referenced by craft_command::create_in_progress_craft().

◆ set_var() [1/6]

void item::set_var ( const std::string &  name,
const std::string &  value 
)

Definition at line 1056 of file item.cpp.

1057{
1058 item_vars[name] = value;
1059}

References item_vars, and om_direction::name().

◆ set_var() [2/6]

void item::set_var ( const std::string &  name,
const tripoint value 
)

Definition at line 1039 of file item.cpp.

1040{
1041 item_vars[name] = string_format( "%d,%d,%d", value.x, value.y, value.z );
1042}
int y
Definition: point.h:137
int x
Definition: point.h:136

References item_vars, om_direction::name(), string_format(), tripoint::x, tripoint::y, and tripoint::z.

◆ set_var() [3/6]

void item::set_var ( const std::string &  name,
double  value 
)

Definition at line 1025 of file item.cpp.

1026{
1027 item_vars[name] = string_format( "%f", value );
1028}

References item_vars, om_direction::name(), and string_format().

◆ set_var() [4/6]

◆ set_var() [5/6]

void item::set_var ( const std::string &  name,
long long  value 
)

Definition at line 1008 of file item.cpp.

1009{
1010 std::ostringstream tmpstream;
1011 tmpstream.imbue( std::locale::classic() );
1012 tmpstream << value;
1013 item_vars[name] = tmpstream.str();
1014}

References item_vars, and om_direction::name().

◆ set_var() [6/6]

void item::set_var ( const std::string &  name,
long  value 
)

Definition at line 1017 of file item.cpp.

1018{
1019 std::ostringstream tmpstream;
1020 tmpstream.imbue( std::locale::classic() );
1021 tmpstream << value;
1022 item_vars[name] = tmpstream.str();
1023}

References item_vars, and om_direction::name().

◆ sight_dispersion()

int item::sight_dispersion ( ) const

Get lowest dispersion of either integral or any attached sights.

Definition at line 7261 of file item.cpp.

7262{
7263 if( !is_gun() ) {
7264 return 0;
7265 }
7266
7267 int res = has_flag( flag_DISABLE_SIGHTS ) ? 90 : type->gun->sight_dispersion;
7268
7269 for( const item *e : gunmods() ) {
7270 const islot_gunmod &mod = *e->type->gunmod;
7271 if( mod.sight_dispersion < 0 || mod.aim_speed < 0 ) {
7272 continue; // skip gunmods which don't provide a sight
7273 }
7274 res = std::min( res, mod.sight_dispersion );
7275 }
7276
7277 return res;
7278}

References flag_DISABLE_SIGHTS(), itype::gun, gunmods(), has_flag(), is_gun(), and type.

Referenced by ranged::get_aim_types(), target_ui::panel_recoil(), print_aim(), and target_ui::run().

◆ simulate_burn()

float item::simulate_burn ( fire_data frd) const

Calculate all burning calculations, but don't actually apply them to item.

DO apply them to fire_data argument, though.

Returns
Amount of "burn" that would be applied to the item.

Definition at line 8231 of file item.cpp.

8232{
8233 const std::vector<material_id> &mats = made_of();
8234 float smoke_added = 0.0f;
8235 float time_added = 0.0f;
8236 float burn_added = 0.0f;
8237 const units::volume vol = base_volume();
8238 const int effective_intensity = frd.contained ? 3 : frd.fire_intensity;
8239 for( const material_id &m : mats ) {
8240 const mat_burn_data &bd = m.obj().burn_data( effective_intensity );
8241 if( bd.immune ) {
8242 // Made to protect from fire
8243 return 0.0f;
8244 }
8245
8246 // If fire is contained, burn rate is independent of volume
8247 if( frd.contained || bd.volume_per_turn == 0_ml ) {
8248 time_added += bd.fuel;
8249 smoke_added += bd.smoke;
8250 burn_added += bd.burn;
8251 } else {
8252 double volume_burn_rate = to_liter( bd.volume_per_turn ) / to_liter( vol );
8253 time_added += bd.fuel * volume_burn_rate;
8254 smoke_added += bd.smoke * volume_burn_rate;
8255 burn_added += bd.burn * volume_burn_rate;
8256 }
8257 }
8258
8259 // Liquids that don't burn well smother fire well instead
8260 if( made_of( LIQUID ) && time_added < 200 ) {
8261 time_added -= rng( 400.0 * to_liter( vol ), 1200.0 * to_liter( vol ) );
8262 } else if( mats.size() > 1 ) {
8263 // Average the materials
8264 time_added /= mats.size();
8265 smoke_added /= mats.size();
8266 burn_added /= mats.size();
8267 } else if( mats.empty() ) {
8268 // Non-liquid items with no specified materials will burn at moderate speed
8269 burn_added = 1;
8270 }
8271
8272 if( count_by_charges() ) {
8273 int stack_burnt = rng( type->stack_size / 2, type->stack_size );
8274 time_added *= stack_burnt;
8275 smoke_added *= stack_burnt;
8276 burn_added *= stack_burnt;
8277 }
8278
8279 frd.fuel_produced += time_added;
8280 frd.smoke_produced += smoke_added;
8281 return burn_added;
8282}
constexpr double to_liter(const volume &v)
Definition: units_volume.h:43
int fire_intensity
Current intensity of the fire.
Definition: fire.h:25
float fuel_produced
Fuel contributed by each burning item this turn is summed here.
Definition: fire.h:29
float smoke_produced
Smoke produced by each burning item this turn is summed here.
Definition: fire.h:27
bool contained
The fire is contained and burned for fuel intentionally.
Definition: fire.h:31
float smoke
Smoke produced per tick when this material burns.
Definition: fire.h:54
float burn
Volume of material destroyed per tick when this material burns.
Definition: fire.h:56

References base_volume(), mat_burn_data::burn, fire_data::contained, count_by_charges(), fire_data::fire_intensity, mat_burn_data::fuel, fire_data::fuel_produced, mat_burn_data::immune, LIQUID, made_of(), rng(), mat_burn_data::smoke, fire_data::smoke_produced, itype::stack_size, units::to_liter(), type, and mat_burn_data::volume_per_turn.

Referenced by burn(), and try_fuel_fire().

◆ spill_contents() [1/2]

bool item::spill_contents ( Character c)

Unloads the item's contents.

Parameters
cCharacter who receives the contents. If c is the player, liquids will be handled, otherwise they will be spilled.
Returns
If the item is now empty.

Definition at line 7059 of file item.cpp.

7060{
7061 if( !is_container() || is_container_empty() ) {
7062 return true;
7063 }
7064
7065 if( c.is_npc() ) {
7066 return spill_contents( c.pos() );
7067 }
7068
7071
7072 return true;
7073}
void handle_liquid_or_spill(Character &guy)
bool spill_contents(Character &c)
Unloads the item's contents.
Definition: item.cpp:7059

References c, contents, item_contents::handle_liquid_or_spill(), is_container(), is_container_empty(), on_contents_changed(), and spill_contents().

Referenced by drop_or_embed_projectile(), pickup::handle_spillable_contents(), Character::i_rem_keep_contents(), pick_one_up(), smash(), and spill_contents().

◆ spill_contents() [2/2]

bool item::spill_contents ( const tripoint pos)

Unloads the item's contents.

Parameters
posPosition to dump the contents on.
Returns
If the item is now empty.

Definition at line 7075 of file item.cpp.

7076{
7077 if( !is_container() || is_container_empty() ) {
7078 return true;
7079 }
7080
7081 for( item *it : contents.all_items_top() ) {
7082 get_map().add_item_or_charges( pos, *it );
7083 }
7084
7086 return true;
7087}

References map::add_item_or_charges(), item_contents::all_items_top(), item_contents::clear_items(), contents, get_map(), is_container(), and is_container_empty().

◆ split()

item item::split ( int  qty)

Splits a count-by-charges item always leaving source item with minimum of 1 charge.

Parameters
qtynumber of required charges to split from source
Returns
new instance containing exactly qty charges or null item if splitting failed

Definition at line 721 of file item.cpp.

722{
723 if( !count_by_charges() || qty <= 0 || qty >= charges ) {
724 return item();
725 }
726 item res = *this;
727 res.charges = qty;
728 charges -= qty;
729 return res;
730}

References charges, count_by_charges(), and item().

Referenced by iexamine::gaspump(), Character::item_reload_cost(), item_location::impl::item_on_map::obtain(), item_location::impl::item_on_person::obtain(), item_location::impl::item_on_vehicle::obtain(), item_location::impl::item_in_container::obtain(), item_location::impl::item_on_map::obtain_cost(), item_location::impl::item_on_person::obtain_cost(), item_location::impl::item_on_vehicle::obtain_cost(), and bandolier_actor::reload().

◆ spoilage_sort_order()

int item::spoilage_sort_order ( ) const

Get time left to rot, ignoring fridge.

Returns time to rot if item is able to, max int - N otherwise, where N is 3 for food, 2 for medication, 1 for other comestibles, 0 otherwise.

Definition at line 5557 of file item.cpp.

5558{
5559 const item *subject;
5560 constexpr int bottom = std::numeric_limits<int>::max();
5561
5562 if( type->container && !contents.empty() ) {
5563 if( type->container->preserves ) {
5564 return bottom - 3;
5565 }
5566 subject = &contents.front();
5567 } else {
5568 subject = this;
5569 }
5570
5571 if( subject->goes_bad() ) {
5572 return to_turns<int>( subject->get_shelf_life() - subject->rot );
5573 }
5574
5575 if( subject->get_comestible() ) {
5576 if( subject->get_category().get_id() == itemcat_food ) {
5577 return bottom - 3;
5578 } else if( subject->get_category().get_id() == itemcat_drugs ) {
5579 return bottom - 2;
5580 } else {
5581 return bottom - 1;
5582 }
5583 }
5584 return bottom;
5585}
static const item_category_id itemcat_drugs("drugs")
static const item_category_id itemcat_food("food")

References itype::container, contents, item_contents::empty(), item_contents::front(), get_category(), get_comestible(), item_category::get_id(), get_shelf_life(), goes_bad(), itemcat_drugs, itemcat_food, rot, and type.

◆ stab_resist()

int item::stab_resist ( bool  to_self = false) const

Definition at line 6092 of file item.cpp.

6093{
6094 // Better than hardcoding it in multiple places
6095 return static_cast<int>( 0.8f * cut_resist( to_self ) );
6096}

References cut_resist().

Referenced by damage_resist().

◆ stacks_with()

bool item::stacks_with ( const item rhs,
bool  check_components = false,
bool  skip_type_check = false 
) const

Definition at line 889 of file item.cpp.

890{
891 if( !skip_type_check && type != rhs.type ) {
892 return false;
893 }
894 if( is_relic() && rhs.is_relic() && !( *relic_data == *rhs.relic_data ) ) {
895 return false;
896 }
897 if( charges != 0 && rhs.charges != 0 && is_money() ) {
898 // Dealing with nonempty cash cards
899 return true;
900 }
901 // This function is also used to test whether items counted by charges should be merged, for that
902 // check the, the charges must be ignored. In all other cases (tools/guns), the charges are important.
903 if( !count_by_charges() && charges != rhs.charges ) {
904 return false;
905 }
906 if( is_favorite != rhs.is_favorite ) {
907 return false;
908 }
909 if( damage_ != rhs.damage_ ) {
910 return false;
911 }
912 if( burnt != rhs.burnt ) {
913 return false;
914 }
915 if( active != rhs.active ) {
916 return false;
917 }
918 if( item_tags != rhs.item_tags ) {
919 return false;
920 }
921 if( faults != rhs.faults ) {
922 return false;
923 }
924 if( techniques != rhs.techniques ) {
925 return false;
926 }
927 if( item_vars != rhs.item_vars ) {
928 return false;
929 }
930 if( goes_bad() && rhs.goes_bad() ) {
931 // Stack items that fall into the same "bucket" of freshness.
932 // Distant buckets are larger than near ones.
933 std::pair<int, clipped_unit> my_clipped_time_to_rot =
935 std::pair<int, clipped_unit> other_clipped_time_to_rot =
936 clipped_time( rhs.get_shelf_life() - rhs.rot );
937 if( my_clipped_time_to_rot != other_clipped_time_to_rot ) {
938 return false;
939 }
940 if( rotten() != rhs.rotten() ) {
941 // just to be safe that rotten and unrotten food is *never* stacked.
942 return false;
943 }
944 }
945 if( ( corpse == nullptr && rhs.corpse != nullptr ) ||
946 ( corpse != nullptr && rhs.corpse == nullptr ) ) {
947 return false;
948 }
949 if( corpse != nullptr && rhs.corpse != nullptr && corpse->id != rhs.corpse->id ) {
950 return false;
951 }
952 if( craft_data_ || rhs.craft_data_ ) {
953 // In-progress crafts are always distinct items. Easier to handle for the player,
954 // and there shouldn't be that many items of this type around anyway.
955 return false;
956 }
957 if( check_components || is_comestible() || is_craft() ) {
958 //Only check if at least one item isn't using the default recipe or is comestible
959 if( !components.empty() || !rhs.components.empty() ) {
961 return false;
962 }
963 }
964 }
966 return false;
967 }
968
969 if( ammo_current() != rhs.ammo_current() ) {
970 return false;
971 }
972
973 return contents.stacks_with( rhs.contents );
974}
std::pair< int, clipped_unit > clipped_time(const time_duration &d)
Returns a value representing the passed in duration truncated to an appropriate unit along with the u...
Definition: calendar.cpp:284
bool stacks_with(const item_contents &rhs) const
std::vector< item_comp > get_uncraft_components() const
Returns a list of components used to craft this item or the default components if it wasn't player-cr...
Definition: item.cpp:10057

References active, ammo_current(), burnt, charges, clipped_time(), components, contents, corpse, count_by_charges(), craft_data_, damage_, faults, get_shelf_life(), get_uncraft_components(), goes_bad(), mtype::id, is_comestible(), is_craft(), is_favorite, is_money(), is_relic(), item_tags, item_vars, item_contents::num_item_stacks(), relic_data, rot, rotten(), item_contents::stacks_with(), techniques, and type.

Referenced by display_stacked_with(), merge_charges(), inventory::restack(), inventory_column::set_stack_favorite(), and npc_trading::transfer_items().

◆ swap_side()

bool item::swap_side ( )

Swap the side on which the item is worn.

Returns false if the item is not sided

Definition at line 830 of file item.cpp.

831{
832 return set_side( opposite_side( get_side() ) );
833}
side opposite_side(side s)
Returns the opposite side.
Definition: bodypart.cpp:30

References get_side(), opposite_side(), and set_side().

Referenced by Character::change_side().

◆ symbol()

const std::string & item::symbol ( ) const

Definition at line 4122 of file item.cpp.

4123{
4124 return type->sym;
4125}
std::string sym
Definition: itype.h:1005

References itype::sym, and type.

Referenced by map::draw_maptile(), map_memory::load_legacy(), mm_elem::operator==(), pickup::pick_up(), mm_submap::serialize(), and debug_menu::wishitem().

◆ tname()

std::string item::tname ( unsigned int  quantity = 1,
bool  with_prefix = true,
unsigned int  truncate = 0 
) const

Return the (translated) item name.

Parameters
quantityused for translation to the proper plural form of the name, e.g. returns "rock" for quantity 1 and "rocks" for quantity > 0.
with_prefixdetermines whether to include more item properties, such as the extent of damage and burning (was created to sort by name without prefix in additional inventory)

Definition at line 4554 of file item.cpp.

4555{
4556 int dirt_level = get_var( "dirt", 0 ) / 2000;
4557 std::string dirt_symbol;
4558 // TODO: MATERIALS put this in json
4559
4560 // these symbols are unicode square characeters of different heights, representing a rough
4561 // estimation of fouling in a gun. This appears instead of "faulty"
4562 // since most guns will have some level of fouling in them, and usually it is not a big deal.
4563 switch( dirt_level ) {
4564 case 0:
4565 dirt_symbol = "";
4566 break;
4567 case 1:
4568 dirt_symbol = "<color_white>\u2581</color>";
4569 break;
4570 case 2:
4571 dirt_symbol = "<color_light_gray>\u2583</color>";
4572 break;
4573 case 3:
4574 dirt_symbol = "<color_light_gray>\u2585</color>";
4575 break;
4576 case 4:
4577 dirt_symbol = "<color_dark_gray>\u2587</color>";
4578 break;
4579 case 5:
4580 dirt_symbol = "<color_brown>\u2588</color>";
4581 break;
4582 default:
4583 dirt_symbol = "";
4584 }
4585 std::string damtext;
4586
4587 // for portions of string that have <color_ etc in them, this aims to truncate the whole string correctly
4588 unsigned int truncate_override = 0;
4589
4590 if( ( damage() != 0 || ( get_option<bool>( "ITEM_HEALTH_BAR" ) && is_armor() ) ) && !is_null() &&
4591 with_prefix ) {
4592 damtext = durability_indicator();
4593 if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
4594 // get the utf8 width of the tags
4595 truncate_override = utf8_width( damtext, false ) - utf8_width( damtext, true );
4596 }
4597 }
4598 if( !faults.empty() ) {
4599 bool silent = true;
4600 for( const auto &fault : faults ) {
4601 if( !fault->has_flag( flag_SILENT ) ) {
4602 silent = false;
4603 break;
4604 }
4605 }
4606 if( silent ) {
4607 damtext.insert( 0, dirt_symbol );
4608 } else {
4609 damtext.insert( 0, _( "faulty " ) + dirt_symbol );
4610 }
4611 }
4612
4613 std::string vehtext;
4614 if( is_engine() && engine_displacement() > 0 ) {
4615 vehtext = string_format( pgettext( "vehicle adjective", "%2.1fL " ),
4616 engine_displacement() / 100.0f );
4617
4618 } else if( is_wheel() && type->wheel->diameter > 0 ) {
4619 vehtext = string_format( pgettext( "vehicle adjective", "%d\" " ), type->wheel->diameter );
4620 }
4621
4622 std::string burntext;
4623 if( with_prefix && !made_of( LIQUID ) ) {
4624 if( volume() >= 1_liter && burnt * 125_ml >= volume() ) {
4625 burntext = pgettext( "burnt adjective", "badly burnt " );
4626 } else if( burnt > 0 ) {
4627 burntext = pgettext( "burnt adjective", "burnt " );
4628 }
4629 }
4630
4631 std::string maintext;
4632 if( is_corpse() || typeId() == itype_blood || item_vars.find( "name" ) != item_vars.end() ) {
4633 maintext = type_name( quantity );
4634 } else if( is_gun() || is_tool() || is_magazine() ) {
4635 int amt = 0;
4636 maintext = label( quantity );
4637 for( const item *mod : is_gun() ? gunmods() : toolmods() ) {
4638 if( !type->gun || !type->gun->built_in_mods.count( mod->typeId() ) ) {
4639 amt++;
4640 }
4641 }
4642 if( amt ) {
4643 maintext += string_format( "+%d", amt );
4644 }
4645 } else if( is_armor() && has_clothing_mod() ) {
4646 maintext = label( quantity ) + "+1";
4647 } else if( is_craft() ) {
4648 maintext = string_format( _( "in progress %s" ), craft_data_->making->result_name() );
4649 if( charges > 1 ) {
4650 maintext += string_format( " (%d)", charges );
4651 }
4652 const int percent_progress = item_counter / 100000;
4653 maintext += string_format( " (%d%%)", percent_progress );
4654 } else if( contents.num_item_stacks() == 1 ) {
4655 const item &contents_item = contents.front();
4656 const unsigned contents_count =
4657 ( ( contents_item.made_of( LIQUID ) || contents_item.is_food() ) &&
4658 contents_item.charges > 1 )
4659 ? contents_item.charges
4660 : quantity;
4661 maintext = string_format( pgettext( "item name", "%2$s (%1$s)" ), label( quantity ),
4662 contents_item.tname( contents_count, with_prefix ) );
4663 } else if( !contents.empty() ) {
4664 maintext = string_format( vpgettext( "item name",
4665 //~ %1$s: item name, %2$zd: content size
4666 "%1$s with %2$zd item",
4667 "%1$s with %2$zd items", contents.num_item_stacks() ),
4668 label( quantity ), contents.num_item_stacks() );
4669 } else {
4670 maintext = label( quantity );
4671 }
4672
4673 avatar &you = get_avatar();
4674 std::string tagtext;
4675 if( is_food() ) {
4677 tagtext += _( " (poisonous)" );
4678 } else if( has_flag( flag_HIDDEN_HALLU ) && you.get_skill_level( skill_survival ) >= 5 ) {
4679 tagtext += _( " (hallucinogenic)" );
4680 }
4681 }
4682 if( is_book() ) {
4683 if( !you.has_identified( typeId() ) ) {
4684 tagtext += _( " (unread)" );
4685 }
4686 }
4687 if( has_var( "bionics_scanned_by" ) && has_flag( flag_CBM_SCANNED ) ) {
4688 tagtext += _( " (bionic detected)" );
4689 }
4690 if( has_flag( flag_ETHEREAL_ITEM ) ) {
4691 tagtext += string_format( _( " (%s turns)" ), get_var( "ethereal" ) );
4692 } else if( goes_bad() || is_food() ) {
4693 if( has_own_flag( "DIRTY" ) ) {
4694 tagtext += _( " (dirty)" );
4695 } else if( rotten() ) {
4696 tagtext += _( " (rotten)" );
4697 } else if( is_going_bad() ) {
4698 tagtext += _( " (old)" );
4699 } else if( is_fresh() ) {
4700 tagtext += _( " (fresh)" );
4701 }
4702 }
4703
4704 const sizing sizing_level = get_sizing( you, get_encumber( you ) != 0 );
4705
4706 if( sizing_level == sizing::human_sized_small_char ) {
4707 tagtext += _( " (too big)" );
4708 } else if( sizing_level == sizing::big_sized_small_char ) {
4709 tagtext += _( " (huge!)" );
4710 } else if( sizing_level == sizing::human_sized_big_char ||
4711 sizing_level == sizing::small_sized_human_char ) {
4712 tagtext += _( " (too small)" );
4713 } else if( sizing_level == sizing::small_sized_big_char ) {
4714 tagtext += _( " (tiny!)" );
4715 } else if( !has_flag( flag_FIT ) && has_flag( flag_VARSIZE ) ) {
4716 tagtext += _( " (poor fit)" );
4717 }
4718
4719 if( is_filthy() ) {
4720 tagtext += _( " (filthy)" );
4721 }
4723 tagtext += _( " (sterile)" );
4724 }
4725
4726 if( is_tool() && has_flag( flag_USE_UPS ) && !has_flag( flag_NAT_UPS ) ) {
4727 tagtext += _( " (UPS)" );
4728 }
4729 if( is_tool() && has_flag( flag_HEATS_FOOD ) ) {
4730 tagtext += _( " (heats)" );
4731 }
4732
4733 if( has_var( "NANOFAB_ITEM_ID" ) ) {
4734 tagtext += string_format( " (%s)", nname( itype_id( get_var( "NANOFAB_ITEM_ID" ) ) ) );
4735 }
4736
4737 if( has_flag( flag_RADIO_MOD ) ) {
4738 tagtext += _( " (radio:" );
4739 if( has_flag( flag_RADIOSIGNAL_1 ) ) {
4740 tagtext += pgettext( "The radio mod is associated with the [R]ed button.", "R)" );
4741 } else if( has_flag( flag_RADIOSIGNAL_2 ) ) {
4742 tagtext += pgettext( "The radio mod is associated with the [B]lue button.", "B)" );
4743 } else if( has_flag( flag_RADIOSIGNAL_3 ) ) {
4744 tagtext += pgettext( "The radio mod is associated with the [G]reen button.", "G)" );
4745 } else {
4746 debugmsg( "Why is the radio neither red, blue, nor green?" );
4747 tagtext += "?)";
4748 }
4749 }
4750
4751 if( has_flag( flag_WET ) ) {
4752 tagtext += _( " (wet)" );
4753 }
4754 if( already_used_by_player( you ) ) {
4755 tagtext += _( " (used)" );
4756 }
4758 tagtext += _( " (lit)" );
4759 } else if( has_flag( flag_IS_UPS ) && get_var( "cable" ) == "plugged_in" ) {
4760 tagtext += _( " (plugged in)" );
4761 } else if( active && !is_food() && !is_corpse() &&
4762 !string_ends_with( typeId().str(), "_on" ) ) {
4763 // Usually the items whose ids end in "_on" have the "active" or "on" string already contained
4764 // in their name, also food is active while it rots.
4765 tagtext += _( " (active)" );
4766 }
4767
4768 if( is_favorite ) {
4769 tagtext += _( " *" ); // Display asterisk for favorite items
4770 }
4771
4772 std::string modtext;
4774 modtext += _( "sawn-off " );
4775 }
4777 modtext += _( "pistol " );
4778 }
4779 if( has_flag( flag_DIAMOND ) ) {
4780 modtext += std::string( pgettext( "Adjective, as in diamond katana", "diamond" ) ) + " ";
4781 }
4782
4783 //~ This is a string to construct the item name as it is displayed. This format string has been added for maximum flexibility. The strings are: %1$s: Damage text (e.g. "bruised"). %2$s: burn adjectives (e.g. "burnt"). %3$s: tool modifier text (e.g. "atomic"). %4$s: vehicle part text (e.g. "3.8-Liter"). $5$s: main item text (e.g. "apple"). %6s: tags (e.g. "(wet) (poor fit)").
4784 std::string ret = string_format( _( "%1$s%2$s%3$s%4$s%5$s%6$s" ), damtext, burntext, modtext,
4785 vehtext, maintext, tagtext );
4786
4787 if( truncate != 0 ) {
4788 ret = utf8_truncate( ret, truncate + truncate_override );
4789 }
4790
4791 if( item_vars.find( "item_note" ) != item_vars.end() ) {
4792 //~ %s is an item name. This style is used to denote items with notes.
4793 return string_format( _( "*%s*" ), ret );
4794 } else {
4795 return ret;
4796 }
4797}
int utf8_width(const char *s, const bool ignore_tags)
std::string utf8_truncate(const std::string &s, size_t length)
bool has_flag(const std::string &flag) const
Definition: fault.h:61
bool is_wheel() const
Definition: item.cpp:6755
bool is_going_bad() const
an item is about to become rotten when shelf life has nearly elapsed
Definition: item.h:845
std::string durability_indicator(bool include_intact=false) const
Provides a prefix for the durability state of the item.
Definition: item.cpp:6316
std::string label(unsigned int quantity=0) const
Returns label from "item_label" itemvar and quantity.
Definition: item.cpp:9952
bool is_fresh() const
an item is fresh if it is capable of rotting but still has a long shelf life remaining
Definition: item.h:840
bool has_clothing_mod() const
Definition: item.cpp:10133
int engine_displacement() const
for combustion engines the displacement (cc)
Definition: item.cpp:4117
bool already_used_by_player(const player &p) const
Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific p...
Definition: item.cpp:8853
static const itype_id itype_blood("blood")
static const std::string flag_SILENT("SILENT")
static const std::string flag_HEATS_FOOD("HEATS_FOOD")
static const itype_id itype_stock_small("stock_small")
static const std::string flag_NAT_UPS("NAT_UPS")
static const itype_id itype_barrel_small("barrel_small")
static const std::string flag_CBM_SCANNED("CBM_SCANNED")
bool string_ends_with(const std::string &s1, const std::string &s2)
Returns true if s1 ends with s2.
Struct used for storing labels (easier to json opposed to a std::map<point, std::string>)
Definition: vehicle.h:579
const char * vpgettext(const char *const context, const char *const msgid, const char *const msgid_plural, const size_t n)
@ silent
Definition: weather_type.h:56

References _, active, already_used_by_player(), big_sized_small_char, burnt, charges, contents, craft_data_, damage(), debugmsg, durability_indicator(), item_contents::empty(), engine_displacement(), fault_bionic_nonsterile, faults, flag_CBM_SCANNED(), flag_DIAMOND(), flag_ETHEREAL_ITEM(), flag_FIT(), flag_HEATS_FOOD(), flag_HIDDEN_HALLU(), flag_HIDDEN_POISON(), flag_IS_UPS(), flag_LITCIG(), flag_NAT_UPS(), flag_RADIO_MOD(), flag_RADIOSIGNAL_1(), flag_RADIOSIGNAL_2(), flag_RADIOSIGNAL_3(), flag_SILENT(), flag_USE_UPS(), flag_VARSIZE(), flag_WATER_EXTINGUISH(), flag_WET(), item_contents::front(), get_avatar(), get_encumber(), get_sizing(), Character::get_skill_level(), get_var(), goes_bad(), itype::gun, gunmod_find(), gunmods(), has_clothing_mod(), has_fault(), fault::has_flag(), has_flag(), avatar::has_identified(), has_own_flag(), has_var(), human_sized_big_char, human_sized_small_char, is_armor(), is_bionic(), is_book(), is_corpse(), is_craft(), is_engine(), is_favorite, is_filthy(), is_food(), is_fresh(), is_going_bad(), is_gun(), is_magazine(), is_null(), is_tool(), is_wheel(), item_counter, item_vars, itype_barrel_small, itype_blood, itype_id, itype_stock_small, label(), LIQUID, made_of(), nname(), item_contents::num_item_stacks(), pgettext(), cata::hash64_detail::ret, rotten(), silent, skill_survival, small_sized_big_char, small_sized_human_char, string_ends_with(), string_format(), tname(), toolmods(), type, type_name(), typeId(), utf8_truncate(), utf8_width(), volume(), vpgettext(), and itype::wheel.

Referenced by Character::absorb_hit(), advanced_inventory::action_examine(), monexamine::add_armor(), game::add_artifact_dreams(), add_disassemblables(), MapgenRemovePartHandler::add_item_or_charges(), advanced_inventory_pane::add_items_from_area(), auto_pickup::player_settings::add_rule(), add_salvagables(), npc::alt_attack(), ammo_consume(), apply_lock_picking_tool(), apply_prying_tool(), Character::armor_absorb(), iuse::artifact(), inventory::assign_empty_invlet(), mattack::bio_op_disarm(), talk_function::bionic_remove(), Character::block_hit(), Character::block_ranged_hit(), iuse::blood_draw(), iuse::burrow(), activity_handlers::butcher_finish(), camp_car_description(), use_function::can_call(), npc::can_read(), repair_item_actor::can_repair_target(), Character::can_unwield(), Character::can_use(), Character::can_wear(), Character::can_wield(), iuse::capture_monster_act(), iuse::capture_monster_veh(), Character::change_side(), charges_per_volume(), iuse::chew(), iuse::coin_flip(), colorized_item_name(), game_menus::inv::compare(), crafting::complete_disassemble(), npc::confident_gun_mode_range(), Character::consume(), Character::consume_item(), iuse::contacts(), game_menus::inv::container_for(), iuse::craft(), auto_pickup::rule_list::create_rule(), iuse::crowbar(), salvage_actor::cut_up(), damage_item(), deactivate(), item_location::impl::item_in_container::describe(), iexamine::dimensional_portal(), iuse::directional_hologram(), display_money(), display_name(), iuse::dive_tank(), npc::do_reload(), draw_bionics_titlebar(), npc::drop_items(), drop_on_map(), drop_or_embed_projectile(), avatar_action::eat(), Character::eat(), iuse::ehandcuffs(), iuse::einktabletpc(), explosion_handler::emp_blast(), npc::execute_action(), Character::extended_description(), iuse::eyedrops(), Character::feed_furnace_with(), fetch_activity(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), npc::find_item(), heal_actor::finish_using(), ranged::fire_gun(), avatar_action::fire_wielded_weapon(), iuse::firecracker_act(), iexamine::fireplace(), iuse::fishing_rod(), iuse::flumed(), iuse::flusleep(), character_funcs::fmt_wielded_weapon(), Character::fuel_bionic_with(), iexamine::fvat_empty(), iexamine::fvat_full(), activity_handlers::game_do_turn(), iuse::gasmask(), generic_multi_activity_do(), avatar::get_book_reader(), get_continue_reqs(), get_encumber_when_containing(), get_making(), get_next_failure_point(), get_owner_name(), get_property_int64_t(), get_remaining_capacity_for_liquid(), vehicle::get_targeting_npc(), talk_function::give_equipment(), monexamine::give_items_to(), iuse::granade_act(), iuse::gun_repair(), avatar_funcs::gunmod_add(), activity_handlers::gunmod_add_finish(), avatar_funcs::gunmod_remove(), ranged::gunmode_checks_common(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), repair_item_actor::handle_components(), handle_craft_failure(), ranged::handle_gun_damage(), liquid_handler::handle_liquid(), Character::handle_melee_wear(), handle_problematic_pickup(), Character::has_enough_charges(), auto_pickup::player_settings::has_rule(), npc::heal_self(), Character::i_add_to_container(), Character::i_rem(), ideal_ranged_dps(), iuse_transform::info(), info(), Character::invoke_item(), avatar::invoke_item(), advanced_inventory_pane::is_filtered(), Character::item_reload_cost(), npc::item_whitelisted(), iuse::jackhammer(), iexamine::keg(), game::list_items(), aim_activity_actor::load_RAS_weapon(), iuse::magic_8_ball(), marloss_common(), iuse::marloss_seed(), character_martial_arts::martialart_use_message(), iuse::meditate(), iuse::melatonin_tablet(), Character::melee_special_effects(), activity_handlers::mend_item_finish(), iuse::mind_splicer(), mod_charges(), mod_last_rot_check(), Character::modify_morale(), iuse::molotov_lit(), npc::mug_player(), iuse::multicooker(), Character::mutation_effect(), npc_throw(), on_wield(), iuse::oxygen_bottle(), iuse::pack_item(), target_ui::panel_gun_info(), parse_tags(), petfood(), pick_one_up(), iuse::pickaxe(), iuse::play_game(), avatar_action::plthrow(), iuse::portable_game(), Character::pour_into(), iexamine::pour_into_keg(), npc::pretend_fire(), game::print_items_info(), game::process_artifact(), process_blackpowder_fouling(), process_extinguish(), map::process_fields_in_submap(), process_internal(), process_litcig(), process_tool(), ranged::prompt_select_default_ammo_for(), mattack::pull_metal_weapon(), put_into_vehicle(), item_reload_option::qty(), iuse::radio_mod(), iuse::radiocar(), character_funcs::rate_sleep_spot(), player::reduce_charges(), avatar_action::reload(), bandolier_actor::reload(), reload(), activity_handlers::reload_finish(), remove_radio_mod(), auto_pickup::player_settings::remove_rule(), repair_item_actor::repair(), activity_handlers::repair_item_finish(), iuse::robotcontrol(), map::rotten_item_spawn(), iuse::rpgdie(), examine_item_menu::run(), iuse::seed(), character_funcs::select_ammo(), talk_effect_fun_t::set_bulk_trade_accept(), talk_effect_fun_t::set_consume_item(), set_item_inventory(), set_item_map(), set_item_map_or_vehicle(), set_mtype(), set_next_failure_point(), talk_effect_fun_t::set_u_buy_item(), gun_actor::shoot(), Character::short_description_parts(), trading_window::show_item_data(), sleep(), smash(), iuse::smoking(), iuse::solarpack(), holster_actor::store(), npc::stow_item(), Character::suffer_from_bad_bionics(), monexamine::take_items_from(), Character::takeoff(), iuse::talking_doll(), tname(), iuse::toggle_heats_food(), tool_info(), iuse::towel_common(), iexamine::tree_maple_tapped(), try_consume(), avatar_funcs::try_disarm_npc(), try_reject_mutagen(), avatar_funcs::try_steal_from_npc(), salvage_actor::try_to_cut_up(), target_ui::uitext_title(), iuse::unfold_generic(), avatar_funcs::unload_item(), iuse::unpack_item(), Character::unwield(), inventory_entry::update_cache(), iuse_transform::use(), countdown_actor::use(), explosion_iuse::use(), unfold_vehicle_iuse::use(), set_transform_iuse::use(), change_scent_iuse::use(), deploy_furn_actor::use(), reveal_map_actor::use(), firestarter_actor::use(), inscribe_actor::use(), holster_actor::use(), ammobelt_actor::use(), heal_actor::use(), place_trap_actor::use(), deploy_tent_actor::use(), saw_barrel_actor::use(), saw_stock_actor::use(), unpack_actor::use(), cast_spell_actor::use(), heal_actor::use_healing_item(), avatar_funcs::use_item(), npc::use_painkiller(), iuse::vibe(), activity_handlers::vibe_do_turn(), Character::wear_item(), iuse::weather_tool(), avatar::wield(), avatar_action::wield(), Character::will_eat(), wind_resist(), debug_menu::wishitem(), memorial_logger::write(), and iuse::xanax().

◆ tool_info()

void item::tool_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3081 of file item.cpp.

3083{
3084 if( !is_tool() ) {
3085 return;
3086 }
3087
3089 if( ammo_capacity() != 0 && parts->test( iteminfo_parts::TOOL_CHARGES ) ) {
3090 info.emplace_back( "TOOL", string_format( _( "<bold>Charges</bold>: %d" ),
3091 ammo_remaining() ) );
3092 }
3093
3094 if( !magazine_integral() ) {
3096 info.emplace_back( "TOOL", _( "Magazine: " ),
3097 string_format( "<stat>%s</stat>", magazine_current()->tname() ) );
3098 }
3099
3101 const std::set<itype_id> compat = magazine_compatible();
3102 info.emplace_back( "TOOL", _( "Compatible magazines: " ),
3103 enumerate_as_string( compat.begin(), compat.end(), []( const itype_id & id ) {
3104 return item::nname( id );
3105 } ) );
3106 }
3107 } else if( ammo_capacity() != 0 && parts->test( iteminfo_parts::TOOL_CAPACITY ) ) {
3108 std::string tmp;
3109 bool bionic_tool = has_flag( flag_USES_BIONIC_POWER );
3110 if( !ammo_types().empty() ) {
3111 //~ "%s" is ammunition type. This types can't be plural.
3112 tmp = vgettext( "Maximum <num> charge of %s.", "Maximum <num> charges of %s.",
3113 ammo_capacity() );
3114 tmp = string_format( tmp, enumerate_as_string( ammo_types().begin(),
3115 ammo_types().end(), []( const ammotype & at ) {
3116 return at->name();
3118
3119 // No need to display max charges, since charges are always equal to bionic power
3120 } else if( !bionic_tool ) {
3121 tmp = vgettext( "Maximum <num> charge.", "Maximum <num> charges.", ammo_capacity() );
3122 }
3123 if( !bionic_tool ) {
3124 info.emplace_back( "TOOL", "", tmp, iteminfo::no_flags, ammo_capacity() );
3125 }
3126 }
3127}

References _, ammo_capacity(), ammo_remaining(), ammo_types(), enumerate_as_string(), flag_USES_BIONIC_POWER(), has_flag(), info(), insert_separation_line(), is_tool(), magazine_compatible(), magazine_current(), magazine_integral(), ammunition_type::name(), iteminfo::no_flags, none, string_format(), iteminfo_query::test(), tname(), TOOL_CAPACITY, TOOL_CHARGES, TOOL_MAGAZINE_COMPATIBLE, TOOL_MAGAZINE_CURRENT, and vgettext().

Referenced by info().

◆ toolmods() [1/2]

std::vector< item * > item::toolmods ( )

Returns all toolmods currently attached to this item (always empty if item not a tool)

Definition at line 5449 of file item.cpp.

5450{
5451 std::vector<item *> res;
5452 if( is_tool() ) {
5453 for( item *e : contents.all_items_top() ) {
5454 if( e->is_toolmod() ) {
5455 res.push_back( e );
5456 }
5457 }
5458 }
5459 return res;
5460}

References item_contents::all_items_top(), contents, and is_tool().

Referenced by ammo_capacity(), ammo_data(), ammo_types(), contents_info(), has_flag(), magazine_compatible(), magazine_default(), magazine_integral(), iuse::remove_all_mods(), tname(), and iuse::toolmod_attach().

◆ toolmods() [2/2]

std::vector< const item * > item::toolmods ( ) const

Definition at line 5462 of file item.cpp.

5463{
5464 std::vector<const item *> res;
5465 if( is_tool() ) {
5466 for( const item *e : contents.all_items_top() ) {
5467 if( e->is_toolmod() ) {
5468 res.push_back( e );
5469 }
5470 }
5471 }
5472 return res;
5473}

References item_contents::all_items_top(), contents, and is_tool().

◆ type_name()

std::string item::type_name ( unsigned int  quantity = 1) const

Name of the item type (not the item), with proper plural.

This is only special when the item itself has a special name ("name" entry in item_tags) or is a named corpse. It's effectively the same as calling nname with the item type id. Use this when the actual item is not meant, for example "The shovel" instead of "Your shovel". Or "The jacket is too small", when it applies to all jackets, not just the one the character tried to wear).

Definition at line 9851 of file item.cpp.

9852{
9853 const auto iter = item_vars.find( "name" );
9854 std::string ret_name;
9855 if( typeId() == itype_blood ) {
9856 if( corpse == nullptr || corpse->id.is_null() ) {
9857 return vpgettext( "item name", "human blood", "human blood", quantity );
9858 } else {
9859 return string_format( vpgettext( "item name", "%s blood",
9860 "%s blood", quantity ),
9861 corpse->nname() );
9862 }
9863 } else if( iter != item_vars.end() ) {
9864 return iter->second;
9865 } else {
9866 ret_name = type->nname( quantity );
9867 }
9868
9869 // Apply conditional names, in order.
9870 for( const conditional_name &cname : type->conditional_names ) {
9871 // Lambda for recursively searching for a item ID among all components.
9872 std::function<bool ( std::list<item> )> component_id_contains =
9873 [&]( std::list<item> components ) {
9874 for( const item &component : components ) {
9875 if( component.typeId().str().find( cname.condition ) != std::string::npos ||
9876 component_id_contains( component.components ) ) {
9877 return true;
9878 }
9879 }
9880 return false;
9881 };
9882 switch( cname.type ) {
9884 if( has_flag( cname.condition ) ) {
9885 ret_name = string_format( cname.name.translated( quantity ), ret_name );
9886 }
9887 break;
9889 if( component_id_contains( components ) ) {
9890 ret_name = string_format( cname.name.translated( quantity ), ret_name );
9891 }
9892 break;
9894 break;
9895 }
9896 }
9897
9898 // Identify who this corpse belonged to, if applicable.
9899 if( corpse != nullptr && has_flag( flag_CORPSE ) ) {
9900 if( corpse_name.empty() ) {
9901 //~ %1$s: name of corpse with modifiers; %2$s: species name
9902 ret_name = string_format( pgettext( "corpse ownership qualifier", "%1$s of a %2$s" ),
9903 ret_name, corpse->nname() );
9904 } else {
9905 //~ %1$s: name of corpse with modifiers; %2$s: proper name; %3$s: species name
9906 ret_name = string_format( pgettext( "corpse ownership qualifier", "%1$s of %2$s, %3$s" ),
9907 ret_name, corpse_name, corpse->nname() );
9908 }
9909 }
9910
9911 return ret_name;
9912}
@ COMPONENT_ID
Definition: itype.h:809
@ FLAG
Definition: itype.h:808
@ num_condition_types
Definition: itype.h:810
std::string condition
Definition: itype.h:823
translation name
Definition: itype.h:826
condition_type type
Definition: itype.h:821
std::vector< conditional_name > conditional_names
Definition: itype.h:918

References COMPONENT_ID, components, conditional_name::condition, itype::conditional_names, corpse, corpse_name, FLAG, flag_CORPSE(), has_flag(), mtype::id, string_id< T >::is_null(), item_vars, itype_blood, conditional_name::name, itype::nname(), mtype::nname(), num_condition_types, pgettext(), string_format(), translation::translated(), type, conditional_name::type, typeId(), and vpgettext().

Referenced by advanced_inventory::action_examine(), Character::can_wear(), game_menus::inv::compare(), avatar::do_read(), talk_function::field_harvest(), activity_handlers::fill_liquid_do_turn(), npc::finish_read(), character_funcs::fmt_wielded_weapon(), trading_window::get_var_trade(), Character::is_snuggling(), inscribe_actor::item_inscription(), label(), game::list_items(), Character::pour_into(), avatar::read(), bandolier_actor::reload(), game_menus::inv::repair(), examine_item_menu::run(), trading_window::show_item_data(), skim_book_msg(), Character::suffer_from_schizophrenia(), tname(), consume_drug_iuse::use(), place_monster_iuse::use(), and bandolier_actor::use().

◆ typeId()

const itype_id & item::typeId ( ) const

return the unique identifier of the items underlying type

Definition at line 8358 of file item.cpp.

8359{
8360 return type ? type->get_id() : itype_id::NULL_ID();
8361}

References itype::get_id(), string_id< itype >::NULL_ID(), and type.

Referenced by computer_session::action_blood_anal(), computer_session::action_data_anal(), add_disassemblables(), inventory::add_item_by_items_type_cache(), map::add_item_or_charges(), add_rain_to_container(), item_pricing::adjust_values(), vehicle_part::ammo_current(), ammo_set(), amount_of_internal(), armor_fit_info(), inventory::assign_empty_invlet(), iexamine::autodoc(), basic_info(), iuse::bell(), mattack::bio_op_takedown(), book_info(), Character::can_fuel_bionic_with(), vehicle_part::can_reload(), bandolier_actor::can_store(), Character::can_use_heal_item(), Character::can_wear(), Character::can_wield(), color_in_inventory(), combat_info(), crafting::complete_disassemble(), Character::compute_nutrient_range(), prepared_item_consumption::consume(), vehicle_part::consume_energy(), consumption_event::consumption_event(), mattack::copbot(), map::create_burnproducts(), iuse::directional_antenna(), disassembly_info(), Character::dismount(), iuse::dive_tank(), avatar::do_read(), npc::do_reload(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), editmap::draw_main_ui_overlay(), iuse::ecig(), iuse::ehandcuffs(), explosion_handler::emp_blast(), computer_session::failure_destroy_blood(), computer_session::failure_destroy_data(), farm_valid_seed(), fetch_activity(), talk_function::field_harvest(), talk_function::field_plant(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), character_funcs::find_ammo_helper(), iexamine::fireplace(), food_info(), Character::fuel_bionic_with(), Character::fun_for(), iexamine::fvat_empty(), iuse::geiger(), json_talk_topic::gen_responses(), generic_multi_activity_do(), Character::get_acquirable_energy(), inventory::get_binned_items(), Character::get_bionic_fueled_with(), character_funcs::get_book_fun_for(), read_inventory_preset::get_denial(), bionic_install_preset::get_failure_chance(), Character::get_overlay_ids(), disassemble_inventory_preset::get_recipe(), get_remaining_capacity_for_liquid(), json_item_substitution::get_substitution(), get_uncraft_components(), give_item_to(), mattack::grab(), iuse::granade_act(), Character::has_active_item(), inventory::has_enough_painkiller(), Character::i_add(), Character::i_add_to_container(), monster::init_from_item(), init_memory_card_with_random_stuff(), io(), advanced_inv_area::is_container_valid(), character_funcs::is_fun_to_read(), is_funnel_container(), is_gunmod_compatible(), read_inventory_preset::is_known(), is_null(), is_reloadable_helper(), ma_requirements::is_valid_character(), item(), Character::item_handling_cost(), iexamine::keg(), ma_style_callback::key(), aim_activity_actor::load_RAS_weapon(), iuse::lumber(), iuse::marloss(), iuse::marloss_gel(), iuse::marloss_seed(), to_cbc_migration::migration_required(), iuse::mind_splicer(), Item_modifier::modify(), advanced_inventory::move_content(), iuse::mp3(), iuse::mp3_on(), item_stack::only_item(), iuse::pack_cbm(), iuse::pack_item(), iexamine::pedestal_temple(), iexamine::pedestal_wyrm(), peek_related_recipe(), pick_usb(), avatar_action::plthrow(), iexamine::pour_into_keg(), process_extinguish(), process_litcig(), examine_item_menu::rate_action_disassemble(), examine_item_menu::rate_action_read(), avatar::read(), game_menus::inv::reassign_letter(), reload(), activity_handlers::reload_finish(), repair_item_actor::repair_recipe_difficulty(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), advanced_inv_area::set_container(), talk_effect_fun_t::set_remove_item_with(), player_morale::set_worn(), iuse::smoking(), iuse::solarpack(), iuse::solarpack_off(), Character::suffer_from_bad_bionics(), Character::suffer_from_radiation(), iuse::talking_doll(), tname(), iuse::toolmod_attach(), toolweapon_off(), toolweapon_on(), iuse::towel_common(), npc_trading::transfer_items(), iexamine::tree_maple_tapped(), disassemble_activity_actor::try_start_single(), salvage_actor::try_to_cut_up(), character_funcs::try_wield_contents(), type_name(), iuse::unpack_item(), inventory::update_cache_with_item(), inventory::update_invlet(), unfold_vehicle_iuse::use(), musical_instrument_actor::use(), unpack_actor::use(), use_amount_internal(), map::use_amount_square(), Character::use_charges(), map::use_charges(), avatar_funcs::use_item(), vehicle::use_washing_machine(), npc::value(), vehicle_part::vehicle_part(), volume(), iuse::water_purifier(), martialart::weapon_valid(), Character::wear_item(), iuse::weather_tool(), avatar::wield(), npc::wield_better_weapon(), and wind_resist().

◆ units_remaining()

int item::units_remaining ( const Character ch,
int  limit = INT_MAX 
) const

How many units (ammo or charges) are remaining?

Parameters
chcharacter responsible for invoking the item
limitstop searching after this many units found
Note
also checks availability of UPS charges if applicable

Definition at line 7992 of file item.cpp.

7993{
7994 if( count_by_charges() ) {
7995 return std::min( static_cast<int>( charges ), limit );
7996 }
7997
7998 int res = ammo_remaining();
7999 if( res < limit && is_power_armor() ) {
8001 res += std::max( ch.charges_of( itype_UPS, limit - res ), ch.charges_of( itype_bio_armor,
8002 limit - res ) );
8003 } else if( character_funcs::can_interface_armor( ch ) ) {
8004 res += ch.charges_of( itype_bio_armor, limit - res );
8005 } else {
8006 res += ch.charges_of( itype_UPS, limit - res );
8007 }
8008 } else if( res < limit && has_flag( flag_USE_UPS ) ) {
8009 res += ch.charges_of( itype_UPS, limit - res );
8010 }
8011
8012 return std::min( static_cast<int>( res ), limit );
8013}
int charges_of(const itype_id &what, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >, std::function< void(int)> visitor=nullptr) const
Count maximum available charges from this instance and any contained items.
Definition: visitable.cpp:944

References ammo_remaining(), character_funcs::can_interface_armor(), charges, visitable< T >::charges_of(), count_by_charges(), flag_USE_UPS(), has_flag(), is_power_armor(), itype_bio_armor, and itype_UPS.

Referenced by iuse::portable_game(), units_sufficient(), iuse_transform::use(), and set_transform_iuse::use().

◆ units_sufficient()

bool item::units_sufficient ( const Character ch,
int  qty = -1 
) const

Check if item has sufficient units (ammo or charges) remaining.

Parameters
chCharacter to check (used if ammo is UPS charges)
qtyunits required, if unspecified use item default

Definition at line 8015 of file item.cpp.

8016{
8017 if( qty < 0 ) {
8018 qty = count_by_charges() ? 1 : ammo_required();
8019 }
8020
8021 return units_remaining( ch, qty ) == qty;
8022}
int units_remaining(const Character &ch, int limit=INT_MAX) const
How many units (ammo or charges) are remaining?
Definition: item.cpp:7992

References ammo_required(), count_by_charges(), and units_remaining().

Referenced by cauterize_actor::can_use(), iuse::gun_repair(), iuse::mp3(), iuse::multicooker(), iuse::noise_emitter_off(), iuse::radglove(), iuse::radio_off(), iuse::radiocontrol(), iuse::remoteveh(), activity_handlers::repair_item_finish(), iuse::robotcontrol(), iuse::shocktonfa_off(), iuse::shocktonfa_on(), iuse::talking_doll(), iuse::tazer(), toolweapon_off(), toolweapon_on(), iuse::vibe(), and iuse::water_purifier().

◆ unset_flag()

item & item::unset_flag ( const std::string &  flag)

◆ unset_flags()

void item::unset_flags ( )

Removes all item specific flags.

Definition at line 5288 of file item.cpp.

5289{
5290 item_tags.clear();
5291}

References item_tags.

Referenced by iuse::camera(), einkpc_download_memory_card(), and iuse::einktabletpc().

◆ update_clothing_mod_val()

void item::update_clothing_mod_val ( )

Definition at line 10150 of file item.cpp.

10151{
10154 type );
10155 float tmp = 0.0;
10156 for( const clothing_mod &cm : clothing_mods::get_all_with( type ) ) {
10157 if( has_own_flag( cm.flag ) ) {
10158 tmp += cm.get_mod_val( type, *this );
10159 }
10160 }
10161 set_var( key, tmp );
10162 }
10163}
clothing_mod_type
Definition: clothing_mod.h:16
const std::vector< clothing_mod > & get_all_with(clothing_mod_type type)
constexpr std::array< clothing_mod_type, 9 > all_clothing_mod_types
Definition: clothing_mod.h:63

References clothing_mods::all_clothing_mod_types, CLOTHING_MOD_VAR_PREFIX(), clothing_mods::get_all_with(), has_own_flag(), set_var(), clothing_mods::string_from_clothing_mod_type(), and type.

Referenced by sew_advanced_actor::use().

◆ use_amount()

bool item::use_amount ( const itype_id it,
int &  quantity,
std::list< item > &  used,
const std::function< bool(const item &)> &  filter = return_true<item> 
)

Consume a specific amount of items of a specific type.

This includes this item, and any of its contents (recursively).

See also
item::use_charges - this is similar for items, not charges.
Parameters
itType of consumable item.
quantityHow much to consumed.
usedOn success all consumed items will be stored here.
filterMust return true for use to occur.

Definition at line 8496 of file item.cpp.

8498{
8499 // Remember quantity so that we can unseal self
8500 int old_quantity = quantity;
8501 std::vector<item *> removed_items;
8502 // First, check contents
8504 [&]( item * a ) {
8505 // visit_items checks the item itself first. we want to do its contents first.
8506 if( a == this ) {
8507 return VisitResponse::NEXT;
8508 }
8509 if( a->use_amount_internal( it, quantity, used, filter ) ) {
8510 removed_items.emplace_back( a );
8511 return VisitResponse::SKIP;
8512 }
8513 return VisitResponse::NEXT;
8514 } );
8515
8516 for( item *remove : removed_items ) {
8517 remove_item( *remove );
8518 }
8519
8520 if( quantity != old_quantity ) {
8522 }
8523 return use_amount_internal( it, quantity, used, filter );
8524}
bool use_amount_internal(const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
Definition: item.cpp:8526
constexpr double a
Definition: magic.cpp:1030

References a, NEXT, on_contents_changed(), visitable< item >::remove_item(), use_amount_internal(), and visitable< item >::visit_items().

Referenced by Character::use_amount().

◆ use_amount_internal()

bool item::use_amount_internal ( const itype_id it,
int &  quantity,
std::list< item > &  used,
const std::function< bool(const item &)> &  filter = return_true<item> 
)
private

Definition at line 8526 of file item.cpp.

8528{
8529 if( typeId() == it && quantity > 0 && filter( *this ) ) {
8530 used.push_back( *this );
8531 quantity--;
8532 return true;
8533 } else {
8534 return false;
8535 }
8536}

References typeId().

Referenced by use_amount().

◆ use_charges()

bool item::use_charges ( const itype_id what,
int &  qty,
std::list< item > &  used,
const tripoint pos,
const std::function< bool(const item &)> &  filter = return_true<item> 
)

Consumes specified charges (or fewer) from this and any contained items.

Parameters
whatspecific type of charge required, e.g. 'battery'
qtymaximum charges to consume. On return set to number of charges not found (or zero)
usedfilled with duplicates of each item that provided consumed charges
posposition at which the charges are being consumed
filterMust return true for use to occur.
Returns
true if this item should be deleted (count-by-charges items with no remaining charges)

Definition at line 8616 of file item.cpp.

8618{
8619 std::vector<item *> del;
8620
8621 visit_items( [&what, &qty, &used, &pos, &del, &filter]( item * e, item * parent ) {
8622 if( qty == 0 ) {
8623 // found sufficient charges
8624 return VisitResponse::ABORT;
8625 }
8626
8627 if( !filter( *e ) ) {
8628 return VisitResponse::NEXT;
8629 }
8630
8631 if( e->is_tool() ) {
8632 if( e->typeId() == what ) {
8633 int n = std::min( e->ammo_remaining(), qty );
8634 qty -= n;
8635
8636 used.push_back( item( *e ).ammo_set( e->ammo_current(), n ) );
8637 e->ammo_consume( n, pos );
8638 }
8639 return VisitResponse::SKIP;
8640
8641 } else if( e->count_by_charges() ) {
8642 if( e->typeId() == what ) {
8643
8644 // if can supply excess charges split required off leaving remainder in-situ
8645 item obj = e->split( qty );
8646 if( parent ) {
8647 parent->on_contents_changed();
8648 }
8649 if( !obj.is_null() ) {
8650 used.push_back( obj );
8651 qty = 0;
8652 return VisitResponse::ABORT;
8653 }
8654
8655 qty -= e->charges;
8656 used.push_back( *e );
8657 del.push_back( e );
8658 }
8659 // items counted by charges are not themselves expected to be containers
8660 return VisitResponse::SKIP;
8661 }
8662
8663 // recurse through any nested containers
8664 return VisitResponse::NEXT;
8665 } );
8666
8667 bool destroy = false;
8668 for( item *e : del ) {
8669 if( e == this ) {
8670 destroy = true; // cannot remove ourselves...
8671 } else {
8672 remove_item( *e );
8673 }
8674 }
8675
8676 return destroy;
8677}

References ABORT, count_by_charges(), is_tool(), NEXT, SKIP, and visitable< item >::visit_items().

Referenced by Character::use_charges(), and use_charges_from_furn().

◆ validate_ownership()

void item::validate_ownership ( ) const

Definition at line 1291 of file item.cpp.

1292{
1293 if( !old_owner.is_null() && !g->faction_manager_ptr->get( old_owner, false ) ) {
1295 }
1296 if( !owner.is_null() && !g->faction_manager_ptr->get( owner, false ) ) {
1297 remove_owner();
1298 }
1299}
void remove_old_owner() const
Definition: item.h:2026
void remove_owner() const
Definition: item.h:2033

References g, string_id< T >::is_null(), old_owner, owner, remove_old_owner(), and remove_owner().

Referenced by get_old_owner(), and get_owner().

◆ volume()

units::volume item::volume ( bool  integral = false) const

Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge.

If trying to determine how many of an item can fit in a given space, charges_per_volume should be used instead.

Parameters
integralif true return effective volume if this item was integrated into another

Definition at line 5104 of file item.cpp.

5105{
5106 if( is_null() ) {
5107 return 0_ml;
5108 }
5109
5110 if( is_corpse() ) {
5111 return corpse_volume( corpse );
5112 }
5113
5114 if( is_craft() ) {
5115 units::volume ret = 0_ml;
5116 for( const item &it : components ) {
5117 ret += it.volume();
5118 }
5119 return ret;
5120 }
5121
5122 const int local_volume = get_var( "volume", -1 );
5124 if( local_volume >= 0 ) {
5125 ret = local_volume * units::legacy_volume_factor;
5126 } else if( integral ) {
5128 } else {
5129 ret = type->volume;
5130 }
5131
5132 if( count_by_charges() || made_of( LIQUID ) ) {
5134 ( charges );
5135 if( type->stack_size <= 0 ) {
5136 debugmsg( "Item type %s has invalid stack_size %d", typeId().str(), type->stack_size );
5137 ret = num;
5138 } else {
5139 ret = num / type->stack_size;
5140 if( num % type->stack_size != 0_ml ) {
5141 ret += 1_ml;
5142 }
5143 }
5144 }
5145
5146 // Non-rigid items add the volume of the content
5147 if( !type->rigid ) {
5149 }
5150
5151 // Some magazines sit (partly) flush with the item so add less extra volume
5152 if( magazine_current() != nullptr ) {
5153 ret += std::max( magazine_current()->volume() - type->magazine_well, 0_ml );
5154 }
5155
5156 if( is_gun() ) {
5157 for( const item *elem : gunmods() ) {
5158 ret += elem->volume( true );
5159 }
5160
5161 // TODO: implement stock_length property for guns
5163 // consider only the base size of the gun (without mods)
5164 ret -= ( type->volume / 3 );
5165 }
5166
5168 ret -= type->gun->barrel_length;
5169 }
5170 }
5171
5172 return ret;
5173}
static const std::string flag_COLLAPSIBLE_STOCK("COLLAPSIBLE_STOCK")
units::volume magazine_well
Volume above which the magazine starts to protrude from the item and add extra volume.
Definition: itype.h:1026
units::volume integral_volume
Space consumed when integrated as part of another item (defaults to volume) CAUTION: value given is f...
Definition: itype.h:979

References charges, components, contents, corpse, corpse_volume(), count_by_charges(), debugmsg, flag_COLLAPSIBLE_STOCK(), get_var(), itype::gun, gunmod_find(), gunmods(), has_flag(), itype::integral_volume, is_corpse(), is_craft(), is_gun(), is_null(), item_contents::item_size_modifier(), itype_barrel_small, units::legacy_volume_factor, LIQUID, made_of(), magazine_current(), itype::magazine_well, num, cata::hash64_detail::ret, itype::rigid, itype::stack_size, type, typeId(), volume(), and itype::volume.

Referenced by activity_on_turn_move_loot(), map::add_item_or_charges(), ranged::aim_cap_from_volume(), attack_cost(), basic_info(), veh_interact::calc_overview(), holster_actor::can_holster(), charges_per_volume(), comestible_inventory_preset::comestible_inventory_preset(), vehicle_part::consume_energy(), salvage_actor::cut_up(), Character::deal_damage(), npc::drop_items(), drop_or_embed_projectile(), fetch_activity(), iexamine::fvat_empty(), Character::get_acquirable_energy(), get_encumber_when_containing(), ranged::get_weapon_dispersion(), monexamine::give_items_to(), repair_item_actor::handle_components(), Character::item_handling_cost(), mdeath::jabberwock(), iexamine::keg(), Character::melee_special_effects(), move_cost_cart(), move_cost_inv(), iexamine::nanofab(), npc_pickup_from_stack(), pickup::obtain_and_tokenize_items(), Character::on_dodge(), on_wield(), vehicle::operate_scoop(), pick_one_up(), pickup::pick_up(), iexamine::pour_into_keg(), Character::power_rating(), process_corpse(), iuse::radiocar(), ready_to_revive(), pickup::reorder_for_dropping(), item_pricing::set_values(), npc::shop_restock(), smash(), holster_actor::store(), npc::stow_item(), stumble(), Character::takeoff(), ranged::throw_item(), Character::throw_range(), ranged::throwing_dispersion(), salvage_actor::time_to_cut_up(), tname(), salvage_actor::try_to_cut_up(), Character::update_bodytemp(), salvage_actor::valid_to_cut_up(), volume(), inventory::volume_without(), and wash_items().

◆ weight()

units::mass item::weight ( bool  include_contents = true,
bool  integral = false 
) const

Definition at line 4958 of file item.cpp.

4959{
4960 if( is_null() ) {
4961 return 0_gram;
4962 }
4963
4964 // Items that don't drop aren't really there, they're items just for ease of implementation
4965 if( has_flag( flag_NO_DROP ) ) {
4966 return 0_gram;
4967 }
4968
4969 if( is_craft() ) {
4970 units::mass ret = 0_gram;
4971 for( const item &it : components ) {
4972 ret += it.weight();
4973 }
4974 return ret;
4975 }
4976
4978 std::string local_str_mass = integral ? get_var( "integral_weight" ) : get_var( "weight" );
4979 if( local_str_mass.empty() ) {
4980 ret = integral ? type->integral_weight : type->weight;
4981 } else {
4982 ret = units::from_milligram( std::stoll( local_str_mass ) );
4983 }
4984
4985 if( has_flag( flag_REDUCED_WEIGHT ) ) {
4986 ret *= 0.75;
4987 }
4988
4989 // if this is a gun apply all of its gunmods' weight multipliers
4990 if( is_gun() ) {
4991 for( const item *mod : gunmods() ) {
4992 ret *= mod->type->gunmod->weight_multiplier;
4993 }
4994 }
4995
4996 if( count_by_charges() ) {
4997 ret *= charges;
4998
4999 } else if( is_corpse() ) {
5000 assert( corpse ); // To appease static analysis
5001 ret = corpse->weight;
5003 ret *= 0.75;
5004 }
5005 if( has_flag( flag_QUARTERED ) ) {
5006 ret /= 4;
5007 }
5008 if( has_flag( flag_GIBBED ) ) {
5009 ret *= 0.85;
5010 }
5011 if( has_flag( flag_SKINNED ) ) {
5012 ret *= 0.85;
5013 }
5014
5015 } else if( magazine_integral() && !is_magazine() ) {
5016 if( ammo_current() == itype_plut_cell ) {
5017 units::mass w = ( *ammo_types().begin() )->default_ammotype()->weight;
5019 } else if( ammo_data() ) {
5021 }
5022 }
5023
5024 // if this is an ammo belt add the weight of any implicitly contained linkages
5025 if( is_magazine() && type->magazine->linkage ) {
5026 item links( *type->magazine->linkage );
5027 links.charges = ammo_remaining();
5028 ret += links.weight();
5029 }
5030
5031 // reduce weight for sawn-off weapons capped to the apportioned weight of the barrel
5033 const units::volume b = type->gun->barrel_length;
5034 const units::mass max_barrel_weight = units::from_gram( to_milliliter( b ) );
5035 const units::mass barrel_weight = units::from_gram( b.value() * type->weight.value() /
5036 type->volume.value() );
5037 ret -= std::min( max_barrel_weight, barrel_weight );
5038 }
5039
5040 if( is_gun() ) {
5041 for( const item *elem : gunmods() ) {
5042 ret += elem->weight( true, true );
5043 }
5044 if( !magazine_integral() && magazine_current() ) {
5045 ret += std::max( magazine_current()->weight(), 0_gram );
5046 }
5047 } else if( include_contents ) {
5049 }
5050
5051 return ret;
5052}
units::mass item_weight_modifier() const
static const std::string flag_NO_DROP("NO_DROP")
static const std::string flag_REDUCED_WEIGHT("REDUCED_WEIGHT")
static const itype_id itype_plut_cell("plut_cell")
constexpr double b
Definition: magic.cpp:1031
constexpr value_type to_milliliter(const quantity< value_type, volume_in_milliliter_tag > &v)
Definition: units_volume.h:38
constexpr quantity< value_type, mass_in_milligram_tag > from_milligram(const value_type v)
Definition: units_mass.h:34
constexpr quantity< value_type, mass_in_milligram_tag > from_gram(const value_type v)
Definition: units_mass.h:41
units::mass integral_weight
Weight difference with the part it replaces for mods.
Definition: itype.h:967
units::mass weight
Definition: mtype.h:264

References ammo_current(), ammo_data(), ammo_remaining(), ammo_types(), b, charges, components, contents, corpse, count_by_charges(), flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_GIBBED(), flag_NO_DROP(), flag_QUARTERED(), flag_REDUCED_WEIGHT(), flag_SKINNED(), units::from_gram(), units::from_milligram(), get_var(), itype::gun, gunmod_find(), gunmods(), has_flag(), itype::integral_weight, is_corpse(), is_craft(), is_gun(), is_magazine(), is_null(), item_contents::item_weight_modifier(), itype_barrel_small, itype_plut_cell, itype::magazine, magazine_current(), magazine_integral(), PLUTONIUM_CHARGES, cata::hash64_detail::ret, units::to_milliliter(), type, units::quantity< V, U >::value(), itype::volume, weight(), itype::weight, and mtype::weight.

Referenced by monexamine::add_armor(), attack_cost(), basic_info(), can_do_activity_there(), holster_actor::can_holster(), Character::can_pick_weight(), veh_interact::can_remove_part(), pickup::cost_to_move_item(), npc::drop_items(), fetch_activity(), funnel_charges_per_turn(), Character::get_acquirable_energy(), Character::get_weight(), monexamine::give_items_to(), is_two_handed(), lift_strength(), Character::melee_attack(), npc_pickup_from_stack(), pick_one_up(), pickup::pick_up(), advanced_inventory::query_charges(), iuse::radiocar(), item_pricing::set_values(), smash(), holster_actor::store(), stumble(), ranged::throw_item(), Character::throw_range(), ranged::throwing_dispersion(), trap::triggered_by_item(), veh_interact::update_part_requirements(), weight(), Character::weight_carried_reduced_by(), and inventory::weight_without().

◆ wheel_area()

int item::wheel_area ( ) const

Returns the total area of this wheel or 0 if it isn't one.

Definition at line 6811 of file item.cpp.

6812{
6813 return is_wheel() ? type->wheel->diameter * type->wheel->width : 0;
6814}

References is_wheel(), type, and itype::wheel.

◆ will_explode_in_fire()

bool item::will_explode_in_fire ( ) const

Definition at line 8734 of file item.cpp.

8735{
8736 if( type->explode_in_fire ) {
8737 return true;
8738 }
8739
8740 if( type->ammo && ( type->ammo->special_cookoff || type->ammo->cookoff ) ) {
8741 return true;
8742 }
8743
8744 // Most containers do nothing to protect the contents from fire
8745 if( !is_magazine() || !type->magazine->protects_contents ) {
8746 return has_item_with( [&]( const item & it ) {
8747 return this != &it && it.will_explode_in_fire();
8748 } );
8749 }
8750
8751 return false;
8752}
bool will_explode_in_fire() const
Definition: item.cpp:8734
bool explode_in_fire
Definition: itype.h:947

References itype::ammo, itype::explode_in_fire, visitable< item >::has_item_with(), is_magazine(), itype::magazine, type, and will_explode_in_fire().

Referenced by will_explode_in_fire().

◆ wind_resist()

int item::wind_resist ( ) const

How resistant clothes made of this material are to wind (0-100)

Definition at line 6780 of file item.cpp.

6781{
6782 std::vector<const material_type *> materials = made_of_types();
6783 if( materials.empty() ) {
6784 debugmsg( "Called item::wind_resist on an item (%s [%s]) made of nothing!", tname(), typeId() );
6785 return 99;
6786 }
6787
6788 int best = -1;
6789 for( const material_type *mat : materials ) {
6790 std::optional<int> resistance = mat->wind_resist();
6791 if( resistance && *resistance > best ) {
6792 best = *resistance;
6793 }
6794 }
6795
6796 // Default to 99% effective
6797 if( best == -1 ) {
6798 return 99;
6799 }
6800
6801 return best;
6802}

References debugmsg, made_of_types(), tname(), and typeId().

Referenced by wind_resistance_from_item_list().

Member Data Documentation

◆ activated_by

safe_reference<Character> item::activated_by

Definition at line 2242 of file item.h.

Referenced by detonate(), itype::invoke(), and explosion_iuse::use().

◆ active

bool item::active = false

Definition at line 2241 of file item.h.

Referenced by activate(), Character::activate_bionic(), map::add_item(), npc::alt_attack(), iexamine::autodoc(), basic_info(), burn(), iuse::c4(), iuse::cable_attach(), holster_actor::can_holster(), countdown_actor::can_use(), check_litcig(), color_in_inventory(), Character::consume_remote_fuel(), deactivate(), mdeath::detonate(), iuse::dive_tank(), iuse::ehandcuffs(), iuse::einktabletpc(), explosion_handler::emp_blast(), Character::find_remote_fuel(), iuse::firecracker(), iuse::firecracker_pack(), iuse::fish_trap(), iuse::gasmask(), iuse::geiger(), iuse::granade(), Character::has_active_item(), io(), enchantment::is_active(), item(), mattack::kamikaze(), make_gun_projectile(), activity_handlers::make_zlave_finish(), iuse::mininuke(), iuse::molotov_lit(), iuse::mp3(), iuse::mp3_on(), iuse::multicooker(), needs_processing(), iuse::noise_emitter_off(), iuse::noise_emitter_on(), on_takeoff(), on_wear(), iuse::pack_item(), process_extinguish(), process_internal(), process_litcig(), process_tool(), process_UPS(), process_wet(), vehicle_part::properties_to_item(), iuse::radio_off(), iuse::radio_on(), iuse::radiocar(), iuse::radiocaron(), iuse::radiocontrol(), read(), iuse::remoteveh(), reset_cable(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), iuse::shocktonfa_off(), iuse::shocktonfa_on(), sleep(), iuse::smoking(), iuse::solarpack_off(), stacks_with(), holster_actor::store(), ranged::throw_item(), iuse::throwable_extinguisher_act(), tname(), toolweapon_off(), toolweapon_on(), iuse::tow_attach(), iuse::towel_common(), avatar_funcs::unload_item(), iuse::unpack_item(), iuse_transform::use(), countdown_actor::use(), fireweapon_off_actor::use(), musical_instrument_actor::use(), and npc::value().

◆ anchor

safe_reference_anchor item::anchor
private

Definition at line 2173 of file item.h.

Referenced by get_safe_reference().

◆ bday

time_point item::bday
private

The time the item was created.

Definition at line 2231 of file item.h.

Referenced by birthday(), io(), item(), legacy_fast_forward_time(), and set_birthday().

◆ burnt

int item::burnt = 0

◆ charges

int item::charges

Definition at line 2203 of file item.h.

Referenced by iuse::acidbomb_act(), act_vehicle_siphon(), Character::activate_bionic(), activity_on_turn_wear(), vehicle::add_charges(), vehicle::add_item(), map::add_item_or_charges(), avatar_funcs::add_or_drop_with_msg(), add_rain_to_container(), ammo_consume(), vehicle_part::ammo_consume(), ammo_remaining(), vehicle_part::ammo_remaining(), ammo_set(), ammo_unset(), item_stack::amount_can_fit(), jmapgen_liquid_item::apply(), are_requirements_nearby(), iuse::arrow_flammable(), basic_info(), burn(), iuse::c4(), bandolier_actor::can_store(), fireweapon_off_actor::can_use(), manualnoise_actor::can_use(), comestible_inventory_preset::comestible_inventory_preset(), complete_craft(), crafting::complete_disassemble(), veh_interact::complete_vehicle(), Character::consume_charges(), vehicle_part::consume_energy(), Character::consume_item(), liquid_handler::consume_liquid(), Character::consume_med(), game_menus::inv::container_for(), count(), activity_handlers::craft_do_turn(), recipe::create_byproducts(), recipe::create_result(), recipe::create_results(), detonate(), mdeath::detonate(), display_name(), iuse::dive_tank(), anonymous_namespace{iexamine.cpp}::atm_menu::do_purchase_card(), npc::do_reload(), veh_interact::do_siphon(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), move_items_activity_actor::do_turn(), throw_activity_actor::do_turn(), anonymous_namespace{iexamine.cpp}::atm_menu::do_withdraw_money(), map::draw_lab(), iuse::ehandcuffs(), explosion_handler::emp_blast(), iuse::eyedrops(), farm_action(), Character::feed_furnace_with(), fetch_activity(), talk_function::field_harvest(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), wash_activity_actor::finish(), heal_actor::finish_using(), iuse::firecracker(), iuse::firecracker_act(), iuse::firecracker_pack(), iuse::firecracker_pack_act(), iuse::fish_trap(), character_funcs::fmt_wielded_weapon(), food_info(), for_each_item_in_both(), inventory::form_from_map(), Character::fuel_bionic_with(), funnel_charges_per_turn(), iexamine::fvat_empty(), iexamine::fvat_full(), iuse::gasmask(), Character::get_acquirable_energy(), activity_handlers::repair_activity_hack::anonymous_namespace{activity_handlers.cpp}::get_fake_tool(), iexamine::get_harvest_items(), liquid_handler::get_liquid_target(), get_remaining_capacity_for_liquid(), inventory_entry::get_selected_charges(), json_item_substitution::get_substitution(), monexamine::give_items_to(), iuse::granade(), iuse::granade_act(), iuse::grenade_inc_act(), hackveh(), liquid_handler::handle_all_liquid(), liquid_handler::handle_liquid_from_container(), pickup::handle_spillable_contents(), has_infinite_charges(), Character::i_add_to_container(), io(), item(), Character::item_reload_cost(), iexamine::keg(), med_info(), merge_charges(), Item_factory::migrate_item(), activity_handlers::milk_finish(), iuse::mininuke(), mod_charges(), mod_damage(), Item_modifier::modify(), iuse::molotov_lit(), advanced_inventory::move_all_items(), advanced_inventory::move_content(), move_item(), iuse::multicooker(), npc_throw(), vehicle::operate_planter(), operator<(), parse_tags(), iexamine::pay_gas(), liquid_handler::perform_liquid_transfer(), pick_one_up(), pickup::pick_up(), map::place_gas_pump(), map::place_toilet(), Character::pour_into(), iexamine::pour_into_keg(), advanced_inventory::print_items(), game::process_artifact(), process_cable(), Character::process_items(), relic_funcs::process_recharge_entry(), map::produce_sap(), vehicle_part::properties_to_item(), item_reload_option::qty(), advanced_inventory::query_charges(), player::reduce_charges(), bandolier_actor::reload(), reload(), remove_ammo(), reset_cable(), mattack::riotbot(), talk_effect_fun_t::set_bulk_trade_accept(), set_countdown(), iexamine::sign(), character_funcs::siphon(), smoker_activate(), map::spawn_an_item(), spell_effect::spawn_ethereal_item(), split(), stacks_with(), Character::suffer_from_bad_bionics(), iuse::tazer2(), Character::throw_range(), iuse::throwable_extinguisher_act(), ranged::throwing_dispersion(), tname(), npc_trading::trade(), npc_trading::transfer_items(), iexamine::tree_maple_tapped(), try_consume(), try_fuel_fire(), units_remaining(), avatar_funcs::unload_item(), inventory::update_quality_cache(), explosion_iuse::use(), place_monster_iuse::use(), fireweapon_off_actor::use(), fireweapon_on_actor::use(), manualnoise_actor::use(), bandolier_actor::use(), emit_actor::use(), sew_advanced_actor::use(), basecamp::use_charges(), map::use_charges(), use_charges_from_furn(), iexamine::use_furn_fake_item(), volume(), iuse::water_purifier(), weight(), Character::weight_carried_reduced_by(), debug_menu::wishitem(), and memorial_logger::write().

◆ components

◆ contents

item_contents item::contents

Definition at line 2165 of file item.h.

Referenced by Character::absorb_hit(), act_vehicle_siphon(), computer_session::action_blood_anal(), computer_session::action_data_anal(), actualize_rot(), vehicle::add_item(), add_rain_to_container(), allow_crafting_component(), ammo_consume(), vehicle_part::ammo_consume(), vehicle_part::ammo_current(), ammo_data(), ammo_remaining(), vehicle_part::ammo_remaining(), vehicle_part::ammo_set(), ammo_unset(), vehicle_part::ammo_unset(), map::bash_items(), iuse::blood_draw(), activity_handlers::butcher_finish(), item_location::impl::item_in_container::calc_index(), veh_interact::calc_overview(), item_funcs::can_be_unloaded(), Character::can_consume(), can_holster(), bandolier_actor::can_store(), can_unload_liquid(), casings_handle(), complete_craft(), veh_interact::complete_vehicle(), Character::compute_nutrient_range(), Character::consume(), npc::consume_cbm_items(), vehicle_part::consume_energy(), contents_info(), contents_made_of(), salvage_actor::cut_up(), damage_item(), item_location::deserialize(), deserialize(), detonate(), display_name(), veh_interact::do_siphon(), avatar_action::eat(), empty_buckets(), computer_session::failure_destroy_blood(), computer_session::failure_destroy_data(), fill_with(), final_info(), character_funcs::find_ammo_helper(), character_funcs::fmt_wielded_weapon(), get_category(), Character::get_consumable_from(), get_contained(), get_encumber(), get_free_mod_locations(), liquid_handler::get_liquid_target(), get_quality(), get_remaining_capacity_for_liquid(), json_item_substitution::get_substitution(), trading_window::get_var_trade(), goes_bad_after_opening(), gunmods(), liquid_handler::handle_liquid_from_container(), Character::handle_melee_wear(), handle_problematic_pickup(), pickup::handle_spillable_contents(), has_effect_when_carried(), Character::i_add_to_container(), info(), is_ammo_container(), is_container_empty(), is_container_full(), advanced_inv_area::is_container_valid(), is_dangerous(), is_food_container(), is_funnel_container(), is_med_container(), is_reloadable_helper(), item_has_uses_recursive(), Character::item_reload_cost(), magazine_current(), item_location::impl::item_in_container::make_dirty(), Character::melee_special_effects(), Item_factory::migrate_item(), activity_handlers::mind_splicer_finish(), advanced_inventory::move_content(), iuse::multicooker(), needs_processing(), on_pickup(), operator<(), peek_related_recipe(), put_in(), item_reload_option::qty(), qualities_info(), iuse::radiocar(), avatar_action::reload(), bandolier_actor::reload(), reload(), item_contents::remove_internal(), visitable< T >::remove_items_with(), character_funcs::select_ammo(), serialize(), advanced_inv_area::set_container(), map::smash_items(), spill_contents(), spoilage_sort_order(), stacks_with(), tname(), toolmods(), iexamine::tree_maple_tapped(), try_consume(), salvage_actor::try_to_cut_up(), character_funcs::try_wield_contents(), avatar_funcs::unload_item(), item_location::impl::item_in_container::unpack(), holster_actor::use(), bandolier_actor::use(), salvage_actor::valid_to_cut_up(), visit_internal(), volume(), iuse::water_purifier(), weight(), npc::wield(), avatar::wield(), avatar_action::wield(), npc::wield_better_weapon(), and memorial_logger::write().

◆ corpse

◆ corpse_name

std::string item::corpse_name
private

Definition at line 2177 of file item.h.

Referenced by get_corpse_name(), io(), and type_name().

◆ craft_data_

◆ curammo

const itype* item::curammo = nullptr
private

Definition at line 2174 of file item.h.

Referenced by ammo_consume(), ammo_data(), ammo_set(), ammo_unset(), gun_info(), io(), and reload().

◆ damage_

int item::damage_ = 0
private

Definition at line 2236 of file item.h.

Referenced by basic_info(), damage(), damage_level(), io(), mod_damage(), on_damage(), set_damage(), and stacks_with().

◆ drop_token

pimpl<item_drop_token> item::drop_token

Two items are dropped in same "batch" if they have identical drop tokens Ideally, this would be stored outside item class.

Definition at line 2254 of file item.h.

Referenced by pickup::obtain_and_tokenize_items(), and pickup::optimize_pickup().

◆ encumbrance_update_

bool item::encumbrance_update_ = false

Definition at line 2219 of file item.h.

Referenced by on_contents_changed().

◆ energy

units::energy item::energy

Definition at line 2204 of file item.h.

Referenced by energy_remaining(), io(), mod_energy(), and process_tool().

◆ faults

◆ frequency

int item::frequency = 0

Definition at line 2209 of file item.h.

Referenced by io(), and iuse::radio_on().

◆ INFINITE_CHARGES

◆ invlet

◆ irradiation

int item::irradiation = 0

Definition at line 2211 of file item.h.

Referenced by armor_fit_info(), and io().

◆ is_favorite

◆ item_counter

◆ item_tags

◆ item_vars

std::map<std::string, std::string> item::item_vars
private

◆ last_rot_check

time_point item::last_rot_check = calendar::turn_zero
private

Time when the rot calculation was last performed.

Definition at line 2229 of file item.h.

Referenced by basic_info(), calc_rot(), io(), item(), legacy_fast_forward_time(), mod_last_rot_check(), process(), process_rot(), and set_relative_rot().

◆ light

light_emission item::light = nolight
private

Definition at line 2237 of file item.h.

Referenced by getlight(), io(), and is_emissive().

◆ mission_id

int item::mission_id = -1

◆ old_owner

faction_id item::old_owner = faction_id::NULL_ID()
mutableprivate

◆ owner

◆ player_id

int item::player_id = -1

Definition at line 2214 of file item.h.

Referenced by mission::deserialize(), io(), and mission::serialize().

◆ poison

◆ recipe_charges

int item::recipe_charges = 1

Definition at line 2206 of file item.h.

Referenced by complete_craft(), Character::compute_effective_nutrients(), and io().

◆ relic_data

◆ rot

time_duration item::rot = 0_turns
private

Accumulated rot, expressed as time the item has been in standard temperature.

It is compared to shelf life (islot_comestible::spoils) to decide if the item is rotten.

Definition at line 2227 of file item.h.

Referenced by basic_info(), minimum_freshness_duration(), spoilage_sort_order(), and stacks_with().

◆ snip_id

snippet_id item::snip_id = snippet_id::NULL_ID()

Definition at line 2210 of file item.h.

Referenced by basic_info(), io(), item(), and set_snippet().

◆ techniques

std::set<matec_id> item::techniques
private

Definition at line 2178 of file item.h.

Referenced by add_technique(), combat_info(), get_techniques(), has_technique(), io(), and stacks_with().

◆ type

const itype* item::type

Definition at line 2164 of file item.h.

Referenced by activate(), npc::activate_item(), actualize_rot(), game::add_artifact_dreams(), map::add_item(), add_monsters(), iuse::adrenaline_injector(), alcohol(), ammo_capacity(), ammo_data(), ammo_default(), ammo_effects(), ammo_required(), ammo_set(), ammo_type(), ammo_types(), iuse::antiasthmatic(), iuse::antibiotic(), iuse::anticonvulsant(), iuse::antifungal(), iuse::antiparasitic(), apply_lock_picking_tool(), armor_info(), armor_protection_info(), iuse::artifact(), iexamine::autodoc(), base_damage_thrown(), base_volume(), basic_info(), battery_info(), iuse::bell(), bionic_info(), talk_function::bionic_install(), iuse::blech(), iuse::blech_because_unclean(), iuse::blood_draw(), iuse::boltcutters(), book_info(), brewing_results(), brewing_time(), mdeath::broken(), burn(), Character::burn_fuel(), iuse::c4(), character_effects::calc_focus_equilibrium(), iuse::call_of_tindalos(), iuse::camera(), item_funcs::can_be_unloaded(), can_contain(), can_do_activity_there(), Character::can_eat(), iuse::can_goo(), can_holster(), npc::can_read(), Character::can_reload(), bandolier_actor::can_store(), fireweapon_off_actor::can_use(), manualnoise_actor::can_use(), install_bionic_actor::can_use(), saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), iuse::capture_monster_act(), charges_per_volume(), check_art_charge_req(), iuse::chew(), iuse::chop_logs(), chop_plank_activity(), iuse::chop_tree(), chop_tree_activity(), iuse::clear_rubble(), color(), color_in_inventory(), combat_info(), common_ammo_default(), prepared_item_consumption::consume(), Character::consume_effects(), Character::consume_med(), iuse::contacts(), contain_monster(), container_info(), convert(), count_by_charges(), activity_handlers::cracking_do_turn(), Character::crit_chance(), iuse::crowbar(), damage_melee(), iuse::datura(), deactivate(), deserialize(), mission::deserialize(), player_morale::morale_point::deserialize(), addiction::deserialize(), vehicle::deserialize(), detonate(), iuse::dig(), iuse::dig_channel(), iuse::directional_antenna(), iuse::directional_hologram(), display_name(), iuse::dive_tank(), avatar::do_read(), iuse::dog_whistle(), game::dump_stats(), Character::eat(), mattack::eat_food(), iuse::ecig(), iuse::ehandcuffs(), iuse::einktabletpc(), emit_radio_signal(), engine_displacement(), Character::enumerate_unmet_requirements(), iuse::extinguisher(), iuse::eyedrops(), faults_potential(), talk_function::field_harvest(), iuse::fill_pit(), final_info(), find_armor_data(), find_best_lock_picking_tool(), npc::find_dangerous_explosives(), npc::finish_read(), heal_actor::finish_using(), avatar_action::fire_wielded_weapon(), iuse::firecracker(), iexamine::fireplace(), iuse::flumed(), iuse::flusleep(), iuse::foodperson(), fuel_energy(), fuel_pump_terrain(), iuse::fungicide(), iuse::gasmask(), iuse::geiger(), json_talk_topic::gen_responses(), Character::get_acquirable_energy(), activatable_inventory_preset::get_action_name(), bionic_install_preset::get_anesth_amount(), bionic_uninstall_preset::get_anesth_amount(), get_available_recipes(), get_base_env_resist(), get_base_env_resist_w_filter(), read_inventory_preset::get_book(), character_funcs::get_book_fun_for(), avatar::get_book_reader(), get_category(), get_chapters(), get_clothing_mod_val(), get_comestible(), get_comestible_fun(), get_container_capacity(), activatable_inventory_preset::get_denial(), read_inventory_preset::get_denial(), bionic_install_preset::get_denial(), bionic_install_surgeon_preset::get_denial(), bionic_uninstall_preset::get_denial(), comestible_inventory_preset::get_edible_comestible(), get_encumber_when_containing(), get_env_resist(), bionic_install_preset::get_failure_chance(), bionic_install_surgeon_preset::get_failure_chance(), bionic_uninstall_preset::get_failure_chance(), ranged::get_fastest_sight(), get_gun_ups_drain(), npc::get_healing_item(), Character::get_hit_weapon(), get_layer(), get_min_str(), get_mod_locations(), ranged::get_most_accurate_sight(), zone_manager::get_near_zone_type_for_item(), bionic_install_preset::get_operation_duration(), bionic_install_surgeon_preset::get_operation_duration(), bionic_uninstall_preset::get_operation_duration(), comestible_inventory_preset::get_order(), get_pet_armor_bodytype(), get_pet_armor_max_vol(), get_pet_armor_min_vol(), get_plant_epoch(), get_plant_name(), get_property_int64_t(), get_property_string(), get_qualities(), get_quality(), get_reload_time(), get_remaining_capacity_for_liquid(), get_storage(), get_techniques(), get_thickness(), get_total_capacity(), get_use_internal(), plot_options::get_zone_name_suggestion(), getGasDiscountCardQuality(), getlight_emit(), goes_bad_after_opening(), iuse::granade(), iuse::granade_act(), gun_damage(), gun_dispersion(), gun_info(), gun_noise(), gun_range(), gun_recoil(), gun_recoil_multiplier(), iuse::gun_repair(), gun_skill(), npc_ai::gun_value(), gunmod_info(), avatar_funcs::gunmod_installation_odds(), iuse::hacksaw(), iuse::hairkit(), iuse::hammer(), iuse::handle_ground_graffiti(), ranged::handle_gun_damage(), has_effect_when_carried(), has_effect_when_wielded(), has_effect_when_worn(), has_explosion_data(), has_flag(), npc::has_healing_options(), has_property(), has_technique(), has_use(), npc::heal_player(), npc::heal_self(), iuse::honeycomb(), in_its_container(), countdown_actor::info(), info(), iuse::inhaler(), inherit_flags(), Character::invoke_item(), avatar::invoke_item(), npc::invoke_item(), io(), is_ammo(), is_artifact(), is_bandolier(), is_battery(), is_bionic(), is_book(), is_brewable(), is_bucket(), is_container(), is_deployable(), is_emissive(), is_engine(), is_fuel(), is_gun(), is_gunmod(), is_holster(), is_magazine(), is_non_resealable_container(), is_null(), avatar_funcs::is_pet_food(), is_seed(), activatable_inventory_preset::is_shown(), is_tool(), is_toolmod(), is_transformable(), is_upgrade(), is_watertight_container(), is_wheel(), item(), item_has_uses_recursive(), Character::item_reload_cost(), item_reload_option::item_reload_option(), iuse::jackhammer(), iuse::jet_injector(), submap::load(), iuse::lumber(), iuse::ma_manual(), made_of(), magazine_compatible(), magazine_default(), magazine_info(), magazine_integral(), iuse::makemound(), mark_chapter_as_read(), iuse::marloss(), iuse::marloss_gel(), iuse::marloss_seed(), max_damage(), iuse::meditate(), Character::meets_requirements(), Character::meets_stat_requirements(), iuse::melatonin_tablet(), npc_ai::melee_value(), iuse::meth(), mill_load_food(), min_damage(), iuse::mind_splicer(), mine_activity(), minimum_freshness_duration(), iuse::mininuke(), mod_damage(), mod_energy(), Item_modifier::modify(), iuse::modify_grid_connections(), Character::modify_morale(), iuse::mop(), avatar_action::move(), iuse::mp3(), iuse::mp3_on(), iuse::multicooker(), mutagen_common_checks(), iuse::mycus(), iuse::noise_emitter_off(), iuse::noise_emitter_on(), on_contents_changed(), on_drop(), on_pickup(), on_takeoff(), on_wear(), on_wield(), operator<(), iuse::oxygen_bottle(), iuse::pheromone(), iuse::plantblech(), iuse::poison(), iuse::portal(), Character::pour_into(), price(), process(), game::process_artifact(), process_cable(), process_extinguish(), process_internal(), Character::process_items(), process_tool(), process_vehicle_items(), process_wet(), vehicle_part::properties_to_item(), iuse::prozac(), iuse::purifier(), iuse::purify_iv(), iuse::purify_smart(), item_reload_option::qty(), qualities_info(), quality_of(), plot_options::query_seed(), iuse::radglove(), iuse::radio_off(), iuse::radio_on(), iuse::radiocar(), iuse::radiocaron(), iuse::radiocontrol(), examine_item_menu::rate_action_use(), rate_food(), read(), avatar::read(), read_inventory_preset::read_inventory_preset(), avatar_action::reload(), reload(), activity_handlers::reload_finish(), iuse::remoteveh(), repair_item_actor::repair_recipe_difficulty(), repaired_with(), reset_cable(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), iuse::robotcontrol(), iexamine::safe(), iuse::seed(), mission::serialize(), player_morale::morale_point::serialize(), addiction::serialize(), vehicle::serialize(), iuse::sewage(), iuse::shavekit(), activity_handlers::shear_finish(), iuse::shocktonfa_off(), sight_dispersion(), simulate_burn(), iuse::siphon(), skim_book_msg(), iuse::sleep(), smoker_activate(), iuse::smoking(), activity_handlers::spellcasting_finish(), spoilage_sort_order(), stacks_with(), activity_handlers::start_fire_do_turn(), activity_handlers::start_fire_finish(), npc::start_read(), iuse::stimpack(), iuse::strong_antibiotic(), symbol(), iuse::talking_doll(), iuse::tazer(), iuse::teleport(), iuse::thorazine(), ranged::throw_item(), ranged::time_to_attack(), npc::time_to_read(), avatar::time_to_read(), tname(), iuse::toolmod_attach(), toolweapon_off(), toolweapon_on(), iuse::towel_common(), try_consume(), type_name(), typeId(), avatar_funcs::unload_item(), target_ui::update_ammo_range_from_gun_mode(), update_clothing_mod_val(), charger_tile::update_internal(), iuse_transform::use(), countdown_actor::use(), consume_drug_iuse::use(), pick_lock_actor::use(), firestarter_actor::use(), fireweapon_off_actor::use(), fireweapon_on_actor::use(), manualnoise_actor::use(), heal_actor::use(), mutagen_actor::use(), mutagen_iv_actor::use(), install_bionic_actor::use(), avatar_funcs::use_item(), vehicle::use_monster_capture(), iuse::vaccine(), npc::value(), iuse::vibe(), volume(), iuse::vortex(), iuse::weak_antibiotic(), npc_ai::weapon_value(), iuse::weed_cake(), weight(), wheel_area(), vehicle_part::wheel_diameter(), vehicle_part::wheel_width(), npc::wield_better_weapon(), npc_ai::wielded_value(), npc::will_accept_from_player(), will_explode_in_fire(), and iuse::xanax().


The documentation for this class was generated from the following files: